React · Middle · Question 17 of 75
How do events behave inside a portal createPortal(child, document.body)?
- ✓Correct answer: They bubble through the React tree to the React parent, not through the DOM
- 2They don't bubble at all - the portal blocks them
- 3They bubble only through the DOM tree up to
document.body
Explanation
A portal renders DOM elsewhere (modals, tooltips, to escape overflow: hidden and stacking contexts), but logically remains part of the React tree: context is available, and events bubble to React ancestors. This is sometimes surprising, e.g. a parent's onClick fires from a click in the modal.