Frontend interview practice question

What runs in React's render phase, and what runs in the commit phase?

HighIntermediateReact

Interview quick answer

Explain what React does in the render phase (call components, compute and diff the next tree, possibly more than once or for nothing) and in the commit phase (apply DOM changes, attach refs, run layout effects synchronously, then passive effects), and where each piece of component code runs.

Interview focus

This React interview question tests whether you can explain React Render Phase vs Commit Phase: What Runs Where, connect it to production trade-offs, and handle common follow-up questions.

  • React Render Phase vs Commit Phase: What Runs Where explanation without falling back to memorized definitions
  • Rendering and Effects reasoning, edge cases, and production failure modes
  • How you would answer the most likely React interview follow-up
Practice more React interview questions
Interview answer drill

Use this React interview question to rehearse a quick answer, common mistake, follow-up, and production pitfall.

Full interview answer

The short answer

In the render phase React calls your components to work out what the UI should look like next and compares the result with the tree on screen. Nothing on the page changes yet (React may create new DOM nodes, but none is attached to the document), and React is free to repeat this work, pause it or throw it away. In the commit phase React applies the differences to the DOM, attaches refs and runs layout effects, all in one synchronous pass; useEffect callbacks run after that, usually once the browser has painted.

The practical rule follows from the split: code in a component body must be safe to run any number of times, and anything that touches the outside world belongs in an effect or an event handler.

Code you write

Phase

When it runs

Sees the new DOM?

Component body

Render

On every render, which can happen more than once or never reach the screen

No

useState initializer, useMemo callback, reducer, setState updater function

Render

Inside renders: the initializer on mount, the memo callback on mount and when its dependencies change, reducers and updater functions when queued updates are processed

No

DOM insertions, updates and removals; useLayoutEffect cleanups

Commit (mutation)

Once per committed update, only for the nodes that changed

Not applicable: this step writes it

Ref attachment (ref.current, ref callbacks)

Commit (layout)

After the DOM changes, children first, so a parent component's layout effect can read the refs in its JSX

Yes

useLayoutEffect, componentDidMount, componentDidUpdate

Commit (layout)

Synchronously, before the browser paints

Yes

useEffect (cleanups first, then setups)

After commit (passive)

Usually after paint; before paint when the update came from a click, a key press or a setState in a layout effect

Yes

Event handlers

Neither

When the event fires; a setState there schedules the next render

Only the last committed DOM

Where each piece of a component runs

Why a render can happen without a commit

A render is React's proposal for the next UI; only a commit makes it real. The common causes of renders that never reach the screen:
1) Interrupted transitions. An update inside startTransition, or one driven by useDeferredValue, renders in small slices. If the user types again before it finishes, React drops the half-built tree and starts over with the newer state.
2) Suspense. A component that suspends abandons its render, and React tries again when the data arrives. Meanwhile it shows the nearest fallback, unless the update is a transition and the boundary already shows content: then the old UI stays on screen and nothing is committed until the new one is ready.
3) StrictMode in development. React calls each component function twice to surface impure renders; production calls it once.

Ordinary updates from a click, a key press or a network response are not sliced: React renders them in one go and commits. Server rendering is render without commit altogether: no effects run and no refs attach on the server.

Worked example: the analytics event that fires too often

A search page updates query inside startTransition so typing stays responsive. The results panel records a view at the top of its body:

JSX
function ResultsPanel({ query }) {
  // ❌ Runs on every render, including renders React throws away
  analytics.track('results_viewed', { query });

  const results = useMemo(() => searchProducts(query), [query]);
  return <ResultList items={results} />;
}
                  

Typing "shoes" quickly can start a transition render for several of the keystrokes, and React abandons the ones a newer keystroke overtakes before they commit. Each abandoned render that reached ResultsPanel still called track, and so does every other render of it, such as a parent re-rendering with the same query, so the dashboard counts views nobody saw. Moving the call into an effect ties it to what was committed:

JSX
function ResultsPanel({ query }) {
  const results = useMemo(() => searchProducts(query), [query]);

  // ✅ Runs after each commit in which the query changed
  useEffect(() => {
    analytics.track('results_viewed', { query });
  }, [query]);

  return <ResultList items={results} />;
}
                  

In development StrictMode still runs that effect setup twice on mount, as a check that its cleanup is right; production records one view per committed query.

Measuring the DOM: which commit-time hook

A tooltip needs its own height before it can decide whether to open above or below its anchor. Read the size in useLayoutEffect: it runs after React has written the DOM but before the browser paints, and a setState inside it renders and commits again before that paint, so the user never sees the tooltip in the wrong place. The same code in useEffect usually paints the first position and then jumps. The trade-off is that every layout effect delays the paint, so keep them for reads and writes the user would otherwise see flicker.

JSX
function Tooltip({ anchorRect, children }) {
  const ref = useRef(null);
  const [placeAbove, setPlaceAbove] = useState(false);

  useLayoutEffect(() => {
    const { height } = ref.current.getBoundingClientRect();
    setPlaceAbove(anchorRect.bottom + height > window.innerHeight);
  }, [anchorRect]);

  return (
    <div ref={ref} className={placeAbove ? 'tooltip above' : 'tooltip below'}>
      {children}
    </div>
  );
}
                  

One committed update, step by step

1) React finishes rendering the new tree off the page.
2) Before mutation: class components can read the old DOM in getSnapshotBeforeUpdate, for example a scroll position.
3) Mutation: React inserts, updates and removes the DOM nodes that changed, detaches refs that changed or whose nodes are removed, and runs useLayoutEffect cleanups and componentWillUnmount. useInsertionEffect, meant for CSS-in-JS libraries, also runs in this step, before any layout effect.
4) React points its root at the new fiber tree, which from now on is the "current" tree that matches the screen.
5) Layout: refs are attached, and useLayoutEffect setups, componentDidMount and componentDidUpdate run.
6) Passive: every useEffect cleanup runs, then every setup. Usually the browser paints first. When the update came from a discrete input such as a click, or a layout effect called setState, React runs them before that paint, at the end of the same task.

Steps 2 to 5 run as one synchronous block. That is what keeps the screen consistent: no paint can show half of the new DOM. In React 19 a ref callback may also return a cleanup function, which React calls when the ref detaches instead of calling the callback with null.

Common pitfalls

• "It re-rendered, so the DOM changed." If a render produces the same output, the commit has nothing to apply to the DOM.
• Reading a ref during render. On the first render it is still null, and on later renders it points at the DOM of the previous commit.
• Calling setState unconditionally in the body. React re-runs that component at once, before its children; without a guard the loop ends in a "Too many re-renders" error.
• "useEffect always runs after paint." Effects caused by a click, or flushed by a layout effect's setState, run before it. When the order matters for what the user sees, use useLayoutEffect.

Follow-up: where does Fiber come in?

The two phases are how React's Fiber reconciler is organized. The render phase walks a tree of fibers, one per component or DOM element, and for transitions it can stop between any two of them; the commit phase applies the finished tree in a few synchronous passes and does not stop. How Fiber schedules that walk is the usual next question, and concurrent rendering is what an interruptible render phase makes possible. For why a component renders in the first place, see why components re-render without prop changes.

Interview framing

Say it like this:
"Render is React calling my components to compute the next tree and diff it against the current one. It never changes the DOM on the page and can be repeated, paused or discarded, so it has to be pure. Commit applies the diff to the DOM in one synchronous pass, attaches refs and runs layout effects before paint; useEffect runs afterwards, usually after paint. So side effects go in effects or event handlers, DOM measurements that affect the first paint go in useLayoutEffect, and I never assume a render reached the screen."

Summary

Render decides, commit applies. Keep render free of side effects; read and write the DOM in useLayoutEffect (part of the commit) when it affects the first paint, and in useEffect (after the commit) otherwise.

Guides
Preparing for interviews?

Built in public

The code behind FrontendAtlas lives on GitHub. A star helps other frontend engineers find it.

Star on GitHub