Explain the use of portals in React and provide use cases.
Instruction: Describe what portals are in React and how they can be used effectively in an application.
Context: This question assesses the candidate's knowledge of React portals, focusing on their use cases and benefits for rendering components outside the DOM hierarchy.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
createPortal renders children into a supplied DOM node while keeping them in their original React tree. Context and React event propagation follow that React tree even though the physical DOM parent is elsewhere.
This complete module demonstrates a nonmodal notice...