4 ms·
React batches updates that were queued from within its own event handlers. So, if you had: setA(1) setB(2) setC(3) in a single click handler, the
by acemarke 7y ago
React batches updates that were queued from within its own event handlers. So, if you had:
setA(1)
setB(2)
setC(3)
in a single click handler, there would be a single render, and a single call to the `useMemo()` callback.
On the other hand, if the state setters were called outside of a React event handler (such as a `setTimeout` or somewhere in an async function), each of those would cause a separate render pass, and the `useMemo` callback would end up being called 3 times.
Note that in the upcoming Concurrent Mode, React will batch updates across event ticks by default.