CodePark/ questions / State
START PRACTICINGPRACTICE
Frontend question · React › State

count is 0. What is it after one click?

function handleClick() {
  setCount(count + 1);
  setCount(count + 1);
}
1

The answer is 1. count is a snapshot for this render, so it is 0 in both lines. Both calls set the state to 0 + 1.

2 is the tempting wrong answer. It assumes the second call sees the first update, but it does not. To add twice, use the updater form
setCount(c => c + 1), which queues each increment on the latest value.