A React event handler is a callback that React remembers for a particular event type and React-managed node. When that event occurs, React invokes the callback with a React event object rather than attaching the callback directly to the DOM node. section 8.2.3
Handling a button click
A JSX button can register a handler such as onClick={handleClick}. React keeps track of that request, detects matching clicks, and calls handleClick. React uses shared document-level listeners instead of creating a separate native listener for every button. section 8.2.3
React’s event system provides two practical differences from direct DOM listeners:
- It reduces memory use by sharing one listener for each event type rather than adding one to every node. section 8.2.3
- It supplies a consistent React event object across browser event behavior. section 8.2.3
Figure 8.4 React doesn’t add a listener on the individual node, but listens to any event on any node, unlike native DOM listeners.
Compare React’s shared event-listening model with native listeners attached directly to individual DOM nodes. section 8.2.3
