How React renders · senior
React events, delegation and portals
React attaches one listener per event type at the root container and dispatches synthetic events through the React tree, so events from a portal bubble to their React parent even though the DOM node lives elsewhere.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Since React 17, React listens at the root container (the element you pass to
createRoot), not atdocument. This makes several React roots and micro-frontends on one page safe. - Synthetic events wrap native events with the same interface. Event pooling was removed in React 17, so you can read
e.targetafter anawait. - Bubbling follows the React component tree. A click inside a portal rendered into
document.bodystill reachesonClickhandlers of its React parents. Context also flows through portals. createPortal(children, domNode)renders children into another DOM node: use it for modals, tooltips and menus that must escapeoverflow: hiddenor stacking contexts.- A native event bubbles from the target up to the React root, then to
document. Soe.stopPropagation()in a React handler does stop nativedocumentlisteners, but native listeners attached directly to inner elements have already run before React saw the event. - Modal accessibility needs more than a portal:
role="dialog",aria-modal, focus moved in and trapped, focus returned on close, Escape closes only the top layer, background madeinert. - React 19.3 Fragment refs give a
FragmentInstancewithaddEventListener,focusand observer methods over a group of children without a wrapper div.
The red pen
Common traps: mistake → fix
Mistake: "React adds a listener to every element"
Fix: one listener per event type at the root.
Mistake: "A click inside a portal can't reach the parent's onClick"
Fix: it bubbles through the React tree to the parent.
Mistake: "Event pooling means I must call
e.persist()"Fix: pooling is gone since React 17.
Easy to hard
Questions interviewers ask, easy to hard
- How does React's event system work, and where are listeners attached since React 17?
- When do you use
createPortal? - A modal is portalled into
document.body. Does a click inside it bubble to the React parent'sonClick? - Nested modals: which one closes on Escape, and how do you trap focus?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.