Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batching update in react-hooks #2

Open
timtnleeProject opened this issue May 20, 2020 · 3 comments
Open

Batching update in react-hooks #2

timtnleeProject opened this issue May 20, 2020 · 3 comments
Labels

Comments

@timtnleeProject
Copy link
Collaborator

Reference: facebook/react#14259

Any state updates triggered inside that callback will be batched. Any state updates triggered outside that callback will not be batched. Timeouts, promises, and async functions will end up executing outside that callback, and therefore not be batched.

Update states multiple times like

setA('a');
setB('b');

within async function like api callback, timer etc...
will not batch updated

We can use useReducer to avoid redundant rendering calls.

@aNyMoRe0505
Copy link
Owner

+1

@timtnleeProject
Copy link
Collaborator Author

See the difference render order
https://codesandbox.io/s/setstate-in-async-callback-z17pk

@timtnleeProject
Copy link
Collaborator Author

react 18 support batch update outside react handlers
reactwg/react-18#21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants