Automatic Batching & Update Scheduling
React can batch multiple state updates so that related changes are processed together. Batching reduces unnecessary work and gives React freedom to schedule updates efficiently.
Do not write code that depends on an immediate DOM update after calling a state setter. If you need the next state for another calculation, use the value you already know or a functional updater. If you need to observe the committed UI, use the appropriate effect or DOM mechanism.
Update scheduling is an implementation detail you should respect rather than circumvent with arbitrary delays.
Key Takeaways
- State updates are scheduled, not immediate mutations.
- Batching reduces redundant rendering work.
- Use explicit lifecycle boundaries instead of timing hacks.