Trace public render semantics versus internals
Public contracts come first
React elements describe desired UI. A component evaluates props and state to produce a description; the renderer applies necessary host changes when work commits. The result is not a DOM node until a DOM renderer creates or reuses one. A render attempt can be abandoned, so do not perform external side effects while calculating JSX. Separate render, commit and browser paint: a component call alone is not proof of any visible change. Effects synchronize committed UI with external systems; layout effects and passive effects have distinct timing rules. Do not infer a universal paint order from console logs. See Chapters 14–16 for the public lifecycle and cleanup contracts.
Trace a ticket counter
// Teaching model: one queue, all updates eligible, no scheduler.export function applyUpdates(initial, updates) { return updates.reduce((value, update) => typeof update === 'function' ? update(value) : update, initial);}This independent reducer is an intentionally simplified explanation of how eligible updates compose, not React source. It ignores lane selection, batching boundaries, eager calculation, rerenders and rebasing. A replacement ignores the prior value; an updater receives it. An updater must be pure.
import React, {useState} from 'react';export default function TicketCounter() { const [count, setCount] = useState(0); return <section><p role="status">Tickets: {count}</p> <button onClick={() => {setCount(count + 1); setCount(count + 1);}}>Add snapshot twice</button> <button onClick={() => {setCount(n => n + 1); setCount(n => n + 1);}}>Add two</button> <button onClick={() => setCount(0)}>Reset</button> </section>;}Starting at zero, pressing Add snapshot twice requests the replacement value 1 twice, so the final committed count should be 1. Reset and press Add two: each updater adds to the accumulated state, giving 2. A handler retains the state captured by its render; it does not gain a new count variable after calling a setter. Verify the visible status after each interaction rather than counting component calls.
import {applyUpdates} from './queue.mjs';const captured = 0;console.log(applyUpdates(captured, [captured+1, captured+1])); // 1console.log(applyUpdates(captured, [n=>n+1,n=>n+1])); // 2console.log(applyUpdates(5, [n=>n+1, 10, n=>n*2])); // 20The last example starts at 5, adds 1, replaces it with 10 and doubles it, giving 20. The model tests only this arithmetic. In a real app a lower-priority update may be deferred and later processed in context; do not conclude that all pending updates execute immediately in one simple reduce. Practice: predict replacement followed by an updater and verify it after a click in an approved React environment.