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

Globally check if any modal is visible #115

Closed osrl closed 9 months ago

osrl commented 1 year ago

Is there nicer a way to check if a modal is open on the page globally? I'm currently using below method

const modals = useContext(NiceModal.NiceModalContext);
const isModalOpen = Object.keys(modals).length > 0

But this requires a new component inside the NiceModal.Provider.

supnate commented 1 year ago

This is the proper way. You can create a custom hook to do the check. Then just use the hook anywhere.