event bubbling
The way an event on an element also triggers handlers on its parent elements, one level at a time up the tree.
In more detail
A click on a button runs handlers on the button, then on its parent, and so on up to the document, unless a handler calls stopPropagation. This lets one listener on a parent handle events for many children. React bubbles its own synthetic events along the component tree, so a click inside a portal still reaches handlers on the component that rendered the portal.
Examples
In the browser: Most events bubble, which is what makes event delegation work: a listener on a list sees clicks on every item. Some events, like focus, blur and scroll on elements, do not. A CustomEvent only bubbles if created with bubbles: true.React events bubble through the React component tree, which is why events from a portal reach its React parent even though its DOM lives elsewhere.Related terms
- event handler — A function that runs when something happens to an element, such as a click (onClick) or a key press (onKeyDown).
- portal — A React feature, createPortal, that renders a component's children into a different place in the DOM, usually document.body.
- SyntheticEvent — The event object React passes to your handlers, a wrapper around the browser native event that behaves the same in every browser.
- event propagation — The journey of an event through the DOM: down from the window to the target (capturing), at the target, then back up (bubbling).
- event delegation — Handling events for many child elements with one listener on a shared ancestor, using event.target to find which child was involved.
- capturing phase — The first phase of event propagation, in which the event travels down from the window through each ancestor toward the target.
- stopPropagation — An event method that stops the event from travelling to further elements, while other listeners on the current element still run.
Taught in
- Overlay Architecture: Portals, Stacking Contexts & Backdrops — Design Systems & Component Engineering
- Event Phases: Capturing, Target And Bubbling Demystified — Frontend Architecture & Web Platform
- Event Delegation: Memory-Efficient Interaction Handlers — Frontend Architecture & Web Platform
- CustomEvent Dispatching And Decoupled Component Event Buses — Frontend Architecture & Web Platform
- SyntheticEvent System: Event Delegation in Modern React — React 19 & Modern Component Architecture
- The use() Hook: Reading Promises And Context Directly — React 19 & Modern Component Architecture
- React Portals: Escaping Stacking Contexts for Modals — React 19 & Modern Component Architecture