React 17 exposes an undocumented API named unstable_batchedUpdates
. It batches multiple useState update calls — inside of asynchronous callbacks — and reduces extraneous renders.
In React 18, all useState
updates are batched, making unstable_batchedUpdates
inert. Remove all uses of unstable_batchedUpdates
.
Instructor: [0:00] React 17 didn't automatically batch updates inside of functions that got called outside of an event handler. This includes setTimeout or any promise-based callback like fetch. In an effort to reduce renders for multiple state updates, we need to wrap our updates in ReactDOM unstable batched updates.
[0:23] This was an undocumented API and largely used by library maintainers. It was a manual way to get the automatic batching that's available in React 18. In React 18, all state updates are batched, no matter where they're called.
[0:40] Let's try this again using the unstable batched updates with the React 18 Root API and see that, effectively, it's a no-op. It's best practice when updating to React 18 to remove these.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!