React's setState Batching: Why setCount(count + 1) Doesn’t Do What You Expect
If you’ve ever written React code that tries to update state multiple times in a row, like this:
setCount(count + 1);
setCount(count + 1);
you might have noticed something strange: the count only increases by 1, not 2. Why is that? Let’s dive into the mechanics of React’