Why does calling the setter twice sometimes add only one?
An event handler sees the state from the render that created it. If count is 0, two calls to setCount(count + 1) both request 1. When each change depends on the previous value, call setCount(previous => previous + 1) twice. React applies the queued updates in order, so the result is 2.

