Home / Articles

What Actually Happens After setState()? React Rendering

What happens after setState in React: the trigger, the render phase, virtual DOM vs real DOM diffing, the commit and where useEffect runs in that order.

Publisher: REACTAPP.TOP16 min read3635 words

This article is published in English.

Sources: What Actually Happens After `setState()`? React Rendering Explained from Virtual DOM to Browser Paint

Use this as an operator-facing rebuild of the ideas in “What Actually Happens After setState()? React Rendering Explained from Virtual DOM to Browser Paint”: clear stages, ordered code slots, and recovery notes that survive a handoff. The Overview stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

setCount(count + 1);

The Big Picture

For the The Big Picture stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

User Click
↓
setState()
↓
React Schedules Update
↓
Render Phase
↓
Virtual DOM
↓
Reconciliation
↓
Commit Phase
↓
Browser Layout
↓
Browser Paint
↓
useEffect()

Step 1: The User Triggers a State Update

For the Step 1 The User stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

function Counter() {
    const [count,setCount]=useState(0);
return (
        <button onClick={()=>setCount(count+1)}>
            {count}
        </button>
    );
}
setCount(count+1);

Step 2: React Starts the Render Phase

For the Step 2 React Starts stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see. For the Step 2 React Starts stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

function Counter(){
console.log("Rendering...");
    const [count,setCount]=useState(0);
    return <button>{count}</button>;
}

What Does “Rendering” Actually Mean?

When working through the What Does Rendering Actually stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Treat effects as synchronization with the outside world, not as a substitute for derived values during render.

Step 3: React Creates a Virtual DOM

When working through the Step 3 React Creates stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Treat effects as synchronization with the outside world, not as a substitute for derived values during render.

return (
    <button>{count}</button>
);
{
    type:"button",
    children:["0"]
}

Step 4: Reconciliation (Diffing)

When working through the Step 4 Reconciliation Diffing stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Treat effects as synchronization with the outside world, not as a substitute for derived values during render. When working through the Step 4 Reconciliation Diffing stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

Previous Virtual DOM
↓
New Virtual DOM
0
↓
1

Why React Is Fast

The Why React Is Fast stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs.

Old UI
↓
Compare
↓
Find Differences
↓
Update Only Those Differences

Step 5: Commit Phase

The Step 5 Commit Phase stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs.

0
↓
1

What Happens Inside the Browser?

The What Happens Inside the stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs. The What Happens Inside the stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

DOM Updated
↓
Style Calculation
↓
Layout
↓
Paint
↓
Composite
↓
Screen Updated

Style Calculation

For the Style Calculation stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

Layout (Reflow)

For the Layout Reflow stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

Paint

For the Paint stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see. For the Paint stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

Composite

When working through the Composite stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Treat effects as synchronization with the outside world, not as a substitute for derived values during render.

Timeline So Far

When working through the Timeline So Far stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Treat effects as synchronization with the outside world, not as a substitute for derived values during render.

User Click
↓
setState()
↓
React Schedules Update
↓
Render Phase
↓
Virtual DOM
↓
Reconciliation
↓
Commit Phase
↓
Browser Layout
↓
Browser Paint
↓
Updated UI

Why React Needs useEffect

When working through the Why React Needs useEffect stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Treat effects as synchronization with the outside world, not as a substitute for derived values during render. When working through the Why React Needs useEffect stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

function Users() {
fetch("/api/users");
    return <div>Loading...</div>;
}

Enter useEffect

The Enter useEffect stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs.

useEffect(() => {
fetch("/api/users");
}, []);

When Does useEffect Run?

The When Does useEffect Run stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs.

Render
↓
useEffect
↓
Paint
Render
↓
Commit
↓
Browser Paint 🎨
↓
useEffect()

Understanding the Dependency Array

The Understanding the Dependency Array stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs. The Understanding the Dependency Array stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

No Dependency Array

For the No Dependency Array stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

useEffect(() => {
console.log("Runs");
});

Empty Dependency Array

For the Empty Dependency Array stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

useEffect(() => {
fetch("/users");
}, []);

Dependencies

For the Dependencies stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

useEffect(() => {
console.log(count);
}, [count]);

For the Dependencies stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

Cleanup Functions

When working through the Cleanup Functions stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Treat effects as synchronization with the outside world, not as a substitute for derived values during render.

useEffect(() => {
window.addEventListener("resize", handleResize);
    return () => {
        window.removeEventListener("resize", handleResize);
    };
}, []);

Common Mistake: Infinite Loops

When working through the Common Mistake Infinite Loops stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Treat effects as synchronization with the outside world, not as a substitute for derived values during render.

useEffect(() => {
setCount(count + 1);
});
Render
↓
Effect
↓
setState()
↓
Render
↓
Effect
↓
setState()
↓
...

useLayoutEffect

When working through the useLayoutEffect stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Treat effects as synchronization with the outside world, not as a substitute for derived values during render. When working through the useLayoutEffect stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

useLayoutEffect(() => {
}, []);

useEffect vs useLayoutEffect

The useEffect vs useLayoutEffect stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs.

useEffect

The useEffect stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs.

Render
↓
Commit
↓
Browser Paint 🎨
↓
useEffect()

useLayoutEffect

The useLayoutEffect stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep render work cheap and push expensive derivation behind memoization only after measuring. Premature memo can hide stale props bugs.

Render
↓
Commit
↓
useLayoutEffect()
↓
Browser Paint 🎨

The useLayoutEffect stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

Why Does This Matter?

For the Why Does This Matter stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

Paint
↓
Measure
↓
Move Tooltip
↓
Paint Again

Using useLayoutEffect

For the Using useLayoutEffect stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

useLayoutEffect(() => {
const height = ref.current.offsetHeight;
}, []);
Render
↓
Commit
↓
Measure DOM
↓
Update Position
↓
Paint Once

Another Real Example

For the Another Real Example stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Colocate state with the component that owns the mutation. Lifting everything to a global store makes timing bugs harder to see.

const inputRef = useRef();
useLayoutEffect(() => {
    inputRef.current.focus();
}, []);

When Should You Use Each Hook?

Rendering Timeline So Far

User Click
↓
setState()
↓
Render Phase
↓
Virtual DOM
↓
Reconciliation
↓
Commit Phase
↓
Browser Layout
↓
useLayoutEffect()
↓
Browser Paint
↓
useEffect()

React Fiber: The Reason Modern React Feels Fast

Large Render
↓
Small Tasks
↓
Pause
↓
Resume
↓
Finish

The React Scheduler

User Typing
↓High Priority
Background List Rendering
↓Lower Priority

Automatic Batching (React 18)

setCount(count + 1);
setName("John");
setLoading(false);
Render
↓
Render
↓
Render
Three Updates
↓
One Render

The Complete Rendering Timeline

User Interaction
↓
setState()
↓
React Scheduler
↓
Render Phase
↓
Component Executes
↓
Virtual DOM Created
↓
Reconciliation
↓
Commit Phase
↓
Real DOM Updated
↓
Browser Style Calculation
↓
Browser Layout (Reflow)
↓
useLayoutEffect()
↓
Browser Paint
↓
Composite
↓
Screen Updated
↓
useEffect()

React vs Browser

Common Misconceptions

Interview Questions

1. What happens after calling setState()?

2. What is the difference between Render Phase and Commit Phase?

3. What is the Virtual DOM?

4. What is Reconciliation?

5. useEffect vs useLayoutEffect

6. Why is the DOM considered expensive?

7. Why did React introduce Fiber?

Final Mental Model

User Click
↓
setState()
↓
React Scheduler
↓
Render Phase
(Component Executes Again)
↓
Virtual DOM
↓
Reconciliation
↓
Commit Phase
↓
Real DOM Updated
↓
Browser Layout
↓
useLayoutEffect()
↓
Browser Paint
↓
useEffect()

Conclusion

Operational checklist