Trace trigger, render and commit
Follow an update from event to screen
React rendering is the calculation of the next UI from props, state and context. A trigger requests work, rendering evaluates components, and a commit applies necessary changes to the host environment (the DOM in React DOM). The browser can then paint the result. These are different activities: a component can render even when its visible output stays unchanged. All examples here are independent App.jsx files for the Chapter 3 setup. Screen results are expected outcomes, not browser test observations.
import { useState } from 'react';function seatLabel(occupied, capacity) { const free = capacity - occupied; return free === 0 ? 'Full' : `${free} ${free === 1 ? 'seat' : 'seats'} free`;}function Availability({ occupied }) { return <p>{seatLabel(occupied, 3)}</p>;}export default function App() { const [occupied, setOccupied] = useState(1); return <main><h1>Reading room</h1><Availability occupied={occupied} /> <button type="button" disabled={occupied >= 3} onClick={() => setOccupied(n => Math.min(n + 1, 3))}>Reserve seat</button> </main>;}Initially the paragraph says 2 seats free. Clicking Reserve seat queues a state update. During render, App and its child describe the next UI using the new occupied value. The commit can change the paragraph to 1 seat free; at capacity the label is Full and the button is disabled. Browser painting is not a call to App. The mental model is: event → update request → UI calculation → DOM commit → browser presentation. React may combine requests or restart calculations; do not infer a fixed number of calls from this sequence.
A render is not necessarily a change to every DOM node
import { useState } from 'react';function RoomHeading() { return <h1>Reading room catalogue</h1>; }export default function App() { const [query, setQuery] = useState(''); return <main><RoomHeading /><label>Filter <input value={query} onChange={e => setQuery(e.target.value)} /></label><p>Filter: {query}</p></main>;}Typing maps updates into the input and filter summary. The heading may be evaluated again without needing any change to its DOM text. React uses element types, keys and tree relationships to reconcile the next description with existing UI; it need not rebuild the page. A commit can have no DOM mutation for a particular component. Browser layout and paint are separate from this reconciliation.
A handler reads the snapshot that created it
import { useState } from 'react';export default function App() { const [count, setCount] = useState(0); const [message, setMessage] = useState('No reservation yet'); function reserve() { setCount(n => n + 1); setMessage(`Before reservation: ${count}`); } return <main><h1>Reservation log</h1><p>Total: {count}</p><p>{message}</p> <button type="button" onClick={reserve}>Reserve</button></main>;}First click: Total: 1 and Before reservation: 0. Second click: Total: 2 and Before reservation: 1. Calling the setter does not rewrite count inside that handler. If you need the next count in this particular synchronous action, derive it explicitly from the known snapshot; do not assume that reading count immediately after its setter is a fresh read. When computing from queued previous state, use a functional updater and keep it pure. Effects (Chapter 15) synchronize after commits; their timing relative to paint depends on circumstances, so do not equate render with effects or assume every effect runs after paint.
Practice
Trace the first reservation in each example. Identify the event, previous snapshot, next UI description and visible changes. Explain why the catalogue heading does not need a DOM text update.