DEV Community

Discussion on: How to Create a Modal in React

Collapse
 
bikasv profile image
Bikas Vaibhav

You should consider portals (reactjs.org/docs/portals.html) for modal as it scopes it out of usual DOM structure including its events.

Collapse
 
franciscomendes10866 profile image
Francisco Mendes • Edited

I considered using it, but since I don't have other elements that use z-index like notifications and toasts, I decided to take a simpler approach. But if I had one of the ones mentioned before, I wouldn't hesitate to use Portals. 😎

Thanks for the comment, it is quite relevant. 🙌

Collapse
 
priya2422 profile image
Priya Pandey

can you tell me if the above solution works which I also did in my practice setup, why would we go for portals instead?