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

Add removeAll() method #140

Closed ArturKustyaev closed 4 months ago

ArturKustyaev commented 6 months ago

Is it possible to add a RemoveAll method that removes all modal windows from their context, for example when changing the page?

supnate commented 6 months ago

To auto hide modal when parent component is destroyed, you need to use the declarative way: https://opensource.ebay.com/nice-modal-react/#declarative

ArturKustyaev commented 6 months ago

To auto hide modal when parent component is destroyed, you need to use the declarative way: https://opensource.ebay.com/nice-modal-react/#declarative

Then what's the point of using the NiceModal.show() approach. For me it is preferable, since I receive data from the callback and, depending on the role, show different drawers:

const updateBranchClickHandler = useCallback((branch: Branch) => {
    if (isUserManager) {
      NiceModal.show(LimitsDrawer, { branch });
    } else {
      NiceModal.show(BranchDrawer, { branch });
    }
  }, []);

The branch property is mandatory and with a declarative approach I won’t be able to push them into the component itself, since I get this property from the callback.