Question · JavaScript and React course · Module 10: React Ecosystem and Future
Rendering a Modal with createPortal
Why is it worth using createPortal to render a modal instead of rendering it directly in the component tree?
Answer options
- A modal rendered through createPortal is not part of the React tree and cannot use context
- createPortal is faster because it does not use the Virtual DOM
- Portal allows rendering a modal outside the parent DOM hierarchy, avoiding issues with overflow: hidden and z-index
- createPortal automatically adds entrance and exit animations to the modal
You can check the correct answer by solving this task in the CodeWorlds game.