Code QuizIntermediate

Functional State Updates

Why multiple sequential updates need the functional form.

Codejavascript
const [count, setCount] = useState(0);

function addThree() {
  setCount(count + 1);
  setCount(count + 1);
  setCount(count + 1);
}
// Expectation: count increases by 3 per press

What is the bug in this code?