State Management · Middle · Question 1 of 75
What will count be after one click if it starts at 0?
function handleClick() {
setCount(count + 1);
setCount((c) => c + 1);
setCount(count + 1);
}- ✓Correct answer:
1 - 2
2 - 3
3
Explanation
Updates are queued in order: count + 1 = 1 (snapshot 0), then c => c + 1 = 2, then count + 1 = 1 again - the last update replaces the value with 1. Mixing snapshot values with updaters gives surprising results; prefer updaters when depending on the previous value.