React · Junior · Question 13 of 75
What will count be after one click if the initial value is 0?
function handleClick() {
setCount(count + 1);
setCount(count + 1);
setCount(count + 1);
}- 1
3 - ✓Correct answer:
1 - 3
0
Explanation
All three calls see the same snapshot count = 0 and queue the value 1 three times. To make updates add up, use the functional form: setCount(c => c + 1) - each call gets the previous result, and the total is 3.