Batch re-renders on state change.
quisido opened this issue · 2 comments
quisido commented
Current behavior:
One component subscribed to two state properties rerenders twice if both change at the same time.
Desired behavior:
It should rerender once.
unstable_batchedUpdates((): void => {
for (const subscription of subscriptions) {
subscription();
}
});
plouh commented
Import from react-dom breaks React Native support. Could the imported function be copied to reactn instead?
quisido commented
Thank you for the report @plouh. This has been reverted. TypeScript does not have as simple of a "conditional import" process as ES6 does, so I'll dwell on this.
unstable_batchedUpdates
in react-dom
allows multiple state changes to result in a single render.
Alternatives:
- Conditionally import from
react-dom
if present. (TypeScript limitation?) - Find an equivalent function in
react
using React Fiber instead of ReactDOM. Preferred, as this will support both React Native and React DOM.