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
- Trigger: initial
root.render,setState,dispatch, context value change, oruseSyncExternalStorestore change. - Schedule: React queues the update with a priority (urgent input vs transition) and batches updates.
- 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.
- Reconcile: diff against the previous fiber tree using element types and keys.
- Commit: apply DOM mutations, update refs (running ref cleanups), run layout effect cleanups and setups.
- Paint: the browser draws the frame.
- Passive effects:
useEffectcleanups 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";23function Child({ value }: { value: number }) {4 console.log(" render Child", value);5 return <p>Child sees {value}</p>;6}78export function RenderCycle() {9 const [value, setValue] = useState(0);10 console.log("1) render RenderCycle", value);1112 useLayoutEffect(() => {13 console.log("3) layout effect (DOM updated, not painted yet)");14 }, [value]);1516 useEffect(() => {17 console.log("4) passive effect (after paint)");18 }, [value]);1920 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.