Course contentsShow
← React
Lesson 436 of 2,39612. Rendering and BatchingFree lesson

State Updates Are Scheduled, Not Immediate

Why calling setState doesn't instantly change the value you read—React schedules the update for the next render.

State Updates Are Scheduled, Not Immediate

What you'll learn: Why reading state immediately after calling setState gives you the old value, not the new one.


When you call setState, it might feel like the state should change right away—but it doesn't. React schedules the update for the next render cycle instead of applying it immediately.

The Core Problem

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

  function handleClick() {
    setCount(count + 1);
    console.log(count); // Still 0, not 1!
  }

  return <button onClick={handleClick}>{count}</button>;
}

When you click the button, console.log(count) prints 0, not 1. Why? Because setCount doesn't instantly update the count variable—it tells React "please update this state in the next render."

The Scheduling Mental Model

Think of setState like ordering food at a restaurant. When you place your order (call setState), the kitchen doesn't instantly teleport food to your table. Your order gets added to a queue, prepared, and then delivered. Similarly, React queues your state update, processes it during the render phase, and commits it during the next render cycle.

Your current render still has the old value. The new value only appears after React completes the render-commit cycle and your component function runs again.

Why React Does This

Scheduling updates allows React to batch multiple setState calls together for better performance. If state changed instantly, React would have to re-render immediately after every single setState—potentially many times per event handler.

Key Takeaway: setState schedules an update, it doesn't mutate state immediately. The current render always sees the old value; the new value appears in the next render.