function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => {
setCount(count + 1);
setCount(count + 1);
}}>{count}</button>
);
}Starting from
count = 0, the button is clicked once. What does it show afterward?- a1✓
- b2
- cNaN
- d0, unchanged
Explanation:Both calls read
count from the same render's snapshot, which is 0 for the whole event. So both calls are effectively setCount(0 + 1); React does not re-run the function body between them, it just schedules the same replacement value twice. The result is 1, not 2. The updater-function form (c => c + 1) is what would make each call build on the previous one.