ForgeFrontend — Prepare, Practice, Crack
Secure checkout
Lifetime access
Instant Drive delivery
Free updates forever

Prepare · Practice · Crack

How does useState work and why is state not updated immediately?

Quick answer

useState returns [value, setter]. The setter schedules a re-render; the variable in the current render is a fixed snapshot, so it updates on the next render.

In detail

Within one render the state value is constant — calling the setter does not mutate it in place, it requests a future render with the new value. That is why reading state right after setting it gives the old value. Each component instance keeps its own independent state, tracked by hook call order.

const [count, setCount] = useState(0);
function handle() {
  setCount(count + 1);
  console.log(count); // still 0 here — snapshot
}

Why interviewers ask this: Tests the 'state as a snapshot' model that trips up most candidates.

Common follow-up questions

  • Why does calling setCount three times only add 1?

This is 1 of 118+ questions in the React Interview Kit

Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.

⚡ Get the React Interview Kit → ₹399

Full kit

React Interview Kit · ₹399

Get it →