Question presented to candidate:
"When you write onClick={e => ...}, what is that e?"
What a strong answer should cover:
- It is not the browser's native event. It is a React wrapper —
SyntheticBaseEvent— with the same interface as the DOM event:type,target,currentTarget,preventDefault(),stopPropagation(). - The native event is still available at
e.nativeEventwhenever you need something React does not surface. - Its original purpose was cross-browser normalisation — one consistent shape and one consistent set of property names across browsers that disagreed.
- Event pooling was removed in React 17. Before that, React reused one object and nulled its fields after the handler, so reading
e.targetafter anawaitgavenulland you needede.persist(). That is now historical. preventDefaultandstopPropagationon the synthetic event do reach the native event.- Names are camelCased (
onClick,onChange) and a few behaviours are normalised — notablyonChange, which fires on every keystroke rather than on blur like the DOMchangeevent.
Clarifying questions expected:
- "Do you need the native event for something specific?" — that decides whether
e.nativeEventcomes up. - "Which React version?" — pooling is the one answer that changed.
Code / implementation expected: No. This is definitional; a one-line snippet is plenty.