0
Challenge · 95React Internals

Synthetic Events

Internalsused in ~60% of apps

You put onClick on a hundred buttons, yet React only ever attaches ONE real listener. The object your handler receives isn't the browser's event either — it's React's own wrapper. Knowing this explains a whole class of confusing bugs.

Core idea. React doesn't bind a listener to every element. It attaches one delegated listener at the root container, lets native events bubble up to it, then wraps each one in a cross-browser SyntheticEvent and dispatches it to your handler.
Playground, this isn't a screenshot
React delegated event system
1 listener @ #rootnot6 per-button
<div id="root">
root.addEventListener("click", dispatch)
</div>
1
Native click on the <button>
the real DOM PointerEvent fires
2
Event bubbles up the DOM tree
button → li → div → … → #root
3
ONE listener on #root catches it
React 17+: delegated at the root container, not document
4
React wraps it → SyntheticEvent
a fresh cross-browser object every time (no pooling)
5
React calls your onClick(e)
you receive the SyntheticEvent, not the native one
Click any of the 6 buttons. They share one real listener at #root — watch the click bubble up, get wrapped, and reach your handler.
clicks dispatched: 0listeners added: 1
↑ play a little first, then dig in