Skip to content

QuizNot attempted

Functional updates chain

After one click, what does the button show?
function App() {
const [count, setCount] = useState(0);
const handleClick = () => {
setCount(c => c + 1);
setCount(c => c + 1);
setCount(c => c + 1);
};
return <button onClick={handleClick}>{count}</button>;
}
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • 3
  • A functional updater receives the latest queued state, so the three c => c + 1 updates chain: 0→1→2→3, in one batched render.
  • Not 1: that is the stale setCount(count + 1) pattern.
  • Not 2: every queued updater runs, none are dropped.
  • Not 0: the updates do apply on the next render.