Remove unstable_batchedUpdates Calls

Michael Chan
InstructorMichael Chan
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

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.