Part 03 / Topic 2 of 7
What actually makes React re-render
useState's array destructuring (const [count, setCount] = useState(0)) gives back the current value and a setter - calling that setter is the one and only signal React looks for to decide "something changed, re-render this component." This is a deliberate design, not an implementation detail you can route around: React does not poll values, does not watch variables, and does not compare anything on its own schedule - it waits to be told. examples/01_state_vs_props.jsx's ClickCounter only ever gets a new count because setCount(count + 1) runs inside its button's onClick; if that line were deleted and count were somehow still incremented some other way (a plain module-level variable, say), the number on screen would never move, no matter how many times the button is clicked. Section 4 below reproduces exactly that failure on purpose, with real state this time instead of a hypothetical.
๐ Going deeper: "re-render" means React calls the component function again, computing a brand-new JSX tree from the current state and props, then efficiently updates only the parts of the real DOM that actually differ (Part 1, section 7, already covered this diffing step) - it does not mean the whole page reloads or every DOM node gets torn down and rebuilt.
Done here? The practice set for Part 3 โ including the solutions โ is on the part page.