eBay / nice-modal-react

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

I want to destroy all the popups that are being displayed when the backend interface 401, how do I do that? #110

Closed mist0616 closed 9 months ago

mist0616 commented 1 year ago

I want to destroy all the popups that are being displayed when the backend interface 401, how do I do that?

ChambreNoire commented 1 year ago

I'm currently facing this issue too. Any advice as to how to destroy all open dialogs would be most appreciated...

mist0616 commented 1 year ago

I'm currently facing this issue too. Any advice as to how to destroy all open dialogs would be most appreciated...

image

I solved this later by rewriting the useModal method...

supnate commented 1 year ago

You can use NiceModalContext to get all modals' ids then hide them.

const modals = useContext(NiceModal.NiceModalContext);

It's in format of { [modalId]: args }.

Below example code opens two modals, then close them in 3 seconds:

useEffect(() => {
   NiceModal.show(MyAntdModal, { name: 'Nate' })
   NiceModal.show(MyAntdDrawer, { name: 'Bood' })
}, [])

const modals = useContext(NiceModal.NiceModalContext);
useEffect(() => {
   setTimeout(() => {
      Object.keys(modals).forEach((mid) => { NiceModal.hide(mid) })
   }, 3000);
}, [modals])