eBay / nice-modal-react

A modal state manager for React.
https://ebay.github.io/nice-modal-react
MIT License
1.96k stars 109 forks source link

defaultVisible #150

Open Staskasnz opened 3 months ago

Staskasnz commented 3 months ago

Hello, I can’t seem to pass the "true" value in defaultVisible to a created and registered modal window, how can I do this correctly? Typescript suggests exactly this method, but no matter how hard I try, I can’t pass the defaultVisible value

const DesktopMenu = loadable(
  () => import('src/entities/menu').then((mod) => mod.DesktopMenu),
  {
    ssr: false,
  }
);

const DesktopMenuWithProps = NiceModal.create(DesktopMenu);

const registar = () => {
  NiceModal.register('desktop-menu', DesktopMenuWithProps, {
    defaultVisible: true,
  });
};

export const ModalProvider: React.FC = ({ children }) => {
  registar();
  return <NiceModal.Provider>{children}</NiceModal.Provider>;
};
supnate commented 3 months ago

defaultVisible is only useful with declarative way: <MyNiceModal defaultVisible .../>

Also, register is expected to be called only once for a modal, don't use it inside a component.

However, to make a modal default visible, you can also use NiceModal.show after registration.

andyyxw commented 2 months ago

defaultVisible is only useful with declarative way: <MyNiceModal defaultVisible .../>

Also, register is expected to be called only once for a modal, don't use it inside a component.

However, to make a modal default visible, you can also use NiceModal.show after registration.

@supnate I don't know how to use defaultVisible in any NiceModal api,can you provide an example for modal default open scene? It seems that because I haven't manually execute the modal.show() , so modal has not mounted at all.