React8h estimated

State & Re-Renders

Difficulty
Importance

The problem

A UI needs to change in response to user interaction — a counter increments, a form field updates — and something needs to trigger the component function to run again and produce a new UI description whenever that internal data changes.

Why now

Variables and state already established a name bound to a value that can change; React's useState is that idea with one crucial addition — changing it doesn't just update a variable, it schedules the component function to run again, which is the entire mechanism that makes a UI 'live' instead of a one-time snapshot.

Mental model

Calling a state setter doesn't mutate anything in place — it tells React 'the next time you call this component function, use this new value instead,' and schedules a re-render. This is why state must be treated as immutable and replaced, not mutated: React's re-render decision is often just comparing the old and new value, and mutating in place would make old and new look identical.

Requires

Helps

Unlocks

Used in

Projects

  • Build a counter component and a todo list component using useState, being careful to replace (not mutate) array state on every update
  • Deliberately mutate array state directly instead of replacing it, observe that the UI fails to update, and explain why

Examples

  • setCount(count + 1) schedules a re-render with the new count; the component function runs again from the top
  • items.push(newItem); setItems(items) fails to trigger a UI update because the array reference didn't change — setItems([...items, newItem]) does

Resources

Mastery checklist