Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Batch re-renders on state change. #129

Closed
quisido opened this issue Sep 14, 2019 · 2 comments
Closed

Batch re-renders on state change. #129

quisido opened this issue Sep 14, 2019 · 2 comments
Assignees
Labels
feature A new feature is requested.
Milestone

Comments

@quisido
Copy link
Collaborator

quisido commented Sep 14, 2019

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();
  }
});
@quisido quisido added the feature A new feature is requested. label Sep 14, 2019
@quisido quisido self-assigned this Sep 14, 2019
@plouh
Copy link

plouh commented Sep 23, 2019

Import from react-dom breaks React Native support. Could the imported function be copied to reactn instead?

@quisido quisido reopened this Sep 24, 2019
@quisido quisido added this to the 3.0.0 milestone Sep 24, 2019
@quisido quisido reopened this Sep 24, 2019
@quisido
Copy link
Collaborator Author

quisido commented Sep 24, 2019

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.

@quisido quisido changed the title Batch re-renders on state change in unstable_batchedUpdates Batch re-renders on state change. Sep 24, 2019
@quisido quisido closed this as completed Nov 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature A new feature is requested.
Projects
None yet
Development

No branches or pull requests

2 participants