React Render Cycle

React · the core model

The screen is a function of state.

Five hooks show how React works. It calls your component again, compares what comes back with what it had, and writes only the difference to the page. Everything else stays where it is.

useState useReducer useRef useMemo useEffect
pure function

Same input, same output

A component takes props and state and returns a description of the UI. It does nothing else while rendering, so React can run it again whenever it needs to.

immutability

New value, never an edit

State is replaced, not changed in place. A new object tells React something changed. The same object tells it nothing did.

render cycle

Trigger, render, commit

A state change starts a render in memory. Only afterwards does React commit the differences to the DOM and let the browser paint.

State

Why state exists

A component is a function that React calls on every render. Each call starts with fresh local variables, so a value you assign inside the function is gone on the next call.

State is the memory of a component between renders.

React keeps the value outside your function, hands it back on every call, and gives you a setter. Calling the setter tells React to run the function again with the new value.

Render 1
Render 2
Render 3
let count = 0local variable, reset by every call
0
0
0
useState(0)kept by React, changed by the setter
0initial value
1after setCount
2after setCount

A snapshot per render

Inside one render, count never changes. setCount(count + 1) asks for the next render, and that render receives the new value.

A setter, not an assignment

count = count + 1 edits a variable that disappears. Only the setter lets React know the screen is out of date.

Render cycle

One pass through the cycle

Every update follows the same six steps. The first three happen in memory. React touches the DOM only at step 4, and only where the new tree differs from the old one.

Trigger Render Diff Commit Paint Effects setState again only the diff UI = f(state) render in memory, commit the minimum
pure, in memory writes the DOM browser hook-driven
  1. 1

    Trigger

    A setter or dispatch is called, or a parent renders. React marks the component as needing a new render.

    useStateuseReducer
  2. 2

    Render

    React calls your component. Same props and state in, same JSX out, with no side effects. The DOM is not touched.

    useStateuseReduceruseMemo
  3. 3

    Diff

    React compares the new element tree with the previous one and keeps a list of what is different.

  4. 4

    Commit

    React writes only that list to the real DOM. Refs to DOM nodes are attached here.

    useRef
  5. 5

    Paint

    The browser draws the pixels that changed.

  6. 6

    Effects

    After paint, each useEffect whose dependencies changed runs. The old cleanup runs first. A setter called here starts the cycle again.

    useEffect

Try it

Click once, watch what React touches

Counter owns the state, so only Counter and its children run again. Header and Footer are not called, and the DOM receives a single text change.

Press the button. The cycle plays slowly, one step at a time.

Components React calls

<App />
<Header />
<Counter />
useState(0), count = 0
<Label />
returns “Count: 0”
<Button />
onClick → setCount

DOM React writes

“Corner Shop”
“Count: 0”
“+1”
“© 2026”
document.titleCount: 0
–of 6 components called
–DOM node changed

Label and Button run again because their parent did. React.memo could skip them, and the DOM would still receive only one text change.

Pure function · Immutability

Two rules that make the cycle safe

React can re-run, compare and skip work only because render has no side effects and state values are never mutated.

Render is a pure function

Same props and state in, same JSX out. No fetching, no timers, no writing to variables outside the component. React may call your component more than once, and in development StrictMode does it on purpose to expose impure code. Side effects belong in event handlers and useEffect.

// pure: safe to run twice
function Total({ price, qty }) {
  return <p>{price * qty}</p>;
}
// impure: changes the outside world
let renders = 0;
function Total({ price }) {
  renders++;
  return <p>{price * Math.random()}</p>;
}

State is replaced, never edited

React decides whether state changed by comparing references with Object.is. The same comparison drives the dependency arrays of useEffect and useMemo.

Mutate: React sees nothing

cart.push("tea");
setCart(cart);
prev @A1=next @A1

Object.is → true. React skips the render and the screen stays stale until something else renders.

Replace: React sees a change

setCart([...cart, "tea"]);
// a new array, a new reference
prev @A1≠next @B2

Object.is → false. React renders, diffs and commits.

Hooks

Five hooks, one cycle

Four hooks let a function remember. One lets it talk to the world outside React.

useStateremember
Manage it.

The basic memory of a component. React stores the value, returns a fixed snapshot on each render, and re-renders when you call the setter with a new value.

const [count, setCount] = useState(0);

setCount(count + 1); // ask for the next render
acts at TriggerRender
useEffectsynchronize
Sync with it.

An effect keeps something outside React (the tab title, a timer, a subscription) in step with state. The dependency array names the state it synchronizes with. If those values are unchanged, the effect is skipped.

useEffect(() => {
  document.title = `Count: ${count}`;
}, [count]); // synchronizes with count
acts at Effects, after paint
useRefremember
Keep it, skip the render.

A box with a .current field. It is the same box on every render, and writing to it does not trigger one. Use it for DOM nodes, timer ids and values the screen does not show.

const clicks = useRef(0);

function onClick() {
  clicks.current += 1; // kept, no render
}
acts at Commithandlers
useMemoremember
Keep the result.

Caches a calculation between renders and reuses it while the dependencies compare equal. Because of Object.is, a new array or object recalculates it. It is an optimization, and React may drop the cache.

const double = useMemo(
  () => slowDouble(count),
  [count]
); // recomputed only if count changes
acts at Render
useReducerremember
Big state, one door.

When many fields change together, every change goes through one pure function: (state, action) => newState. The reducer returns a new object, so immutability is built into the pattern, and every transition has a name.

function reducer(state, action) {
  switch (action.type) {
    case "add":
      return { ...state, items: [...state.items, action.item] };
    case "clear":
      return { ...state, items: [] };
  }
}
const [cart, dispatch] = useReducer(reducer, { items: [] });
dispatch({ type: "add", item: "tea" });
acts at TriggerRender

Across renders

What each hook does over three renders

One component with count, a cart, a clicks ref, a memoized double and an effect on [count].

Render 1mount
Render 2one click: count 0 → 1, item added
Render 3an unrelated state changes
useStatecount
0 initial value, used once
1 new snapshot from the setter
1 same value returned
useReducercart
{ items: [] } initial state
new object returned by the reducer
same object nothing dispatched
useRefclicks
{ current: 0 } box created
same box the handler wrote 1, no render caused
same box still 1
useMemodouble
computes 0
computes 2 count changed
reuses 2 count is the same
useEffect[count]
runs after paint
cleanup, then runs count changed
skipped count is the same

The whole model

React does not redraw the page.

It re-runs a pure function, compares two descriptions of the UI, and writes the difference. Hooks decide what the function remembers and what it connects to.

event→setState→render→diff→commit→paint→effect

Hooks that remember

useStateuseReduceruseRefuseMemo

State and reducer hold what the screen shows. Ref and memo hold what survives between renders without being shown.

Hooks that connect

useEffect

Effects keep the outside world in step with state.