ReactMedium

What is the render cycle?

The render cycle is how React turns a state change into updated pixels: an update is triggered, React renders the affected components to compute new JSX, reconciles it with the previous tree, commits the DOM changes, and then runs layout effects, lets the browser paint, and runs passive effects.

Steps

  1. Trigger: initial root.render, setState, dispatch, context value change, or useSyncExternalStore store change.
  2. Schedule: React queues the update with a priority (urgent input vs transition) and batches updates.
  3. Render: React calls the component that changed and its descendants (unless memoized), producing new elements. This phase must be pure and may be paused, restarted or thrown away.
  4. Reconcile: diff against the previous fiber tree using element types and keys.
  5. Commit: apply DOM mutations, update refs (running ref cleanups), run layout effect cleanups and setups.
  6. Paint: the browser draws the frame.
  7. Passive effects: useEffect cleanups and setups run.

What does not re-render

Parents and siblings of the updated component, unless they also changed. Memoized children with equal props also skip rendering.

Concurrent features

  • Transitions render in the background and can be interrupted by urgent updates.
  • Suspense boundaries can show fallbacks while parts of the tree wait for data.
  • <Activity mode="hidden"> content renders at low priority and keeps state without running effects.

Interview tip

Separate "render" (calling your function) from "commit" (touching the DOM). A component can render without anything changing in the DOM.

Code example

tsx
1import { useEffect, useLayoutEffect, useState } from "react";
2
3function Child({ value }: { value: number }) {
4 console.log(" render Child", value);
5 return <p>Child sees {value}</p>;
6}
7
8export function RenderCycle() {
9 const [value, setValue] = useState(0);
10 console.log("1) render RenderCycle", value);
11
12 useLayoutEffect(() => {
13 console.log("3) layout effect (DOM updated, not painted yet)");
14 }, [value]);
15
16 useEffect(() => {
17 console.log("4) passive effect (after paint)");
18 }, [value]);
19
20 return (
21 <div>
22 {/* 2) commit: React updates only the text nodes that changed */}
23 <button onClick={() => setValue((v) => v + 1)}>Trigger update</button>
24 <Child value={value} />
25 </div>
26 );
27}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.

Open in study app