React · Middle · Question 17 of 75

How do events behave inside a portal createPortal(child, 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.

Further reading

Problem with a question

React · Middle · question 17

Test yourself

Take the React · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz