liveBook · Manning

Event

As explained in React Quickly, Second Edition

A change event is a browser event dispatched when the value of a form control changes.

Handle a button click

A handler runs when an event occurs. In React, assign the function to an event property on a JSX element: const [counter, setCounter] = useState(0); const onClick = () => setCounter(value => value + 1); return <button onClick={onClick}>Increment: {counter}</button>; Pass the function as onClick; the click triggers the state update. section 8.1.1

An event reports an interaction or change. A button can dispatch a click event when activated by mouse, touch, or keyboard; a form control’s change event reports a changed value. Other events can report mouse movement, form submission, or a video starting to play. React connects supported events to handlers through JSX properties such as onClick, onChange, and onPlay. section 8.0 section 8.1.1

React calls a handler with an event object. Use it to identify the event and its target, inspect its propagation phase, or prevent a browser default action. For example, preventing the default action of a link click stops navigation. Events travel through ancestor elements during capture, reach the target, then travel back during bubbling; a listener’s phase determines when it runs. section 8.11 section 8.4.3

Prefer JSX event properties for supported events: React manages those listeners as components mount and unmount. Use a manually attached JavaScript listener when the target is outside React’s control, such as window or document, or when React does not support the event type. A manual listener also needs manual removal. section 8.1 section 8.8

How React Quickly, Second Edition covers it

How deep it goes
Explains JSX listeners, React event objects, propagation, default actions, and when to attach listeners manually.
Examples
Uses a counter button, mouse-movement status, video playback controls, and link navigation.
What it assumes
Builds on JSX, HTML elements, and a counter with state while introducing how its click handler works.
What you can do after
Apply it via React JSX handlers to respond to supported events, or attach JavaScript listeners for targets outside React.
How it connects
Links JSX event properties with state, DOM event listeners, event propagation, and browser default actions.

Also explained in

Compare how 18 books explain event →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React Quickly, Second Edition. The section links point to the parts of the book it draws on.