What happens when a React component re-renders?

HardReact FundamentalsTheory Question

Hint

Separate trigger, render and commit. Which of the three actually touches the DOM?

Full Answer

A React update happens in three steps:

  1. Trigger — the initial root.render(), or a state update (setState, a reducer dispatch, a context change).
  2. Render — React calls the component function again (and its children's), producing a new element tree, then reconciles it against the previous one to find what changed. No DOM changes happen here.
  3. Commit — React applies the minimal set of DOM changes, then runs layout effects and, after paint, regular effects.
function Counter() {
  const [count, setCount] = useState(0);
  console.log('render', count); // runs on every render

  useEffect(() => {
    document.title = 'Count: ' + count; // runs after commit
  }, [count]);

  return <button onClick={() => setCount(c => c + 1)}>{count}</button>;
}

What re-renders: the component whose state changed and, by default, every component below it — even if their props are the same. React.memo lets a child skip re-rendering when its props are shallow-equal.

Setting state to the same value (by Object.is) lets React bail out without re-rendering the children.

💡 "Render" doesn't mean "DOM update". A component can render many times while the DOM changes only when the output differs.

More React Fundamentals Questions

Practice this in a timed sprint

5 free questions, no signup required