-
Notifications
You must be signed in to change notification settings - Fork 49k
Description
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.