question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider exporting `batchedUpdates` from React

See original GitHub issue

ReactDOM and React Native both currently export an unstable_batchedUpdates API. Because batching is a renderer/reconciliation-level concern, this API is exported by the renderer packages, not the core react package.

The React team has recently encouraged the Redux team to make use of unstable_batchedUpdates in React-Redux. However, this becomes complicated due to how that API is being exported.

It’s possible to deal with this at the bundler level. Some experimentation shows that creating an alternate file with a .native.js extension will cause that to be picked up by the RN bundler, as in this example:

// batch.js
import {unstable_batchedUpdates} from "./react-dom";

// ./react-dom.js
export {unstable_batchedUpdates} from "react-dom"

// ./react-dom.native.js
export {unstable_batchedUpdates} from "react-native"

However, this does not handle the case where an alternative React renderer is being used. The list of other React renderers is continuing to grow, which means that a React library that needs batching would have to deal with that situation in some way. This becomes extremely complicated when you start considering variations on bundlers, module formats, and build environments.

It would be extremely beneficial if the React core itself exported a batchedUpdates API. That could default to being a noop wrapper like (callback) => callback() if no suitable implementation was available.

I know that unstable_batchedUpdates() is, uh… “unstable”. However, the React team has stated that “it’s the most stable of the unstable APIs”, and “half of Facebook depends on this”.

I think it would really help the ecosystem if some form of this API was solidified and exported from the core React package itself.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
gaearoncommented, Mar 30, 2022

In React 18, updates are batched automatically, so we don’t need to expose this. The unstable_ method doesn’t do anything when you use createRoot. We’re not removing it yet because libraries use it, but you can drop it once you stop supporting <18.

1reaction
danielkczcommented, Feb 29, 2020

What do you mean? The batchedUpdates is not officially stable yet, but nobody is stopping to use it 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

React v18.0 – React Blog
Batching is when React groups multiple state updates into a single re-render for better performance. Without automatic batching, we only  ...
Read more >
Simplifying state management in React apps with batched ...
In this post we will take a closer look at the batched updates feature and demonstrate how it simplifies the statement management and ......
Read more >
React Batching - Robin Wieruch
Batching in React describes the internal implementation detail of React which treats multiple state updates as one state update.
Read more >
Embed isnt working correctly in react app - Stack Overflow
here is the button in my functional component import React from 'react' import './SideshiftStyle.css' export default function Sideshift() ...
Read more >
react-batched-updates - npm Package Health Analysis - Snyk
Learn more about react-batched-updates: package health score, popularity, ... project maintenance signal to consider for react-batched-updates is that it ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found