-
Notifications
You must be signed in to change notification settings - Fork 49.4k
Closed
Description
Do you want to request a feature or report a bug?
bug + improvement
What is the current behavior?
Sometimes state updates caused by multiple calls to useState
setter, are not batched.
sandbox1: https://codesandbox.io/s/8yy0nw2m28
sandbox2: https://codesandbox.io/s/1498n44yr3
Step to reproduce: click on increment all
text and check the console
diff:
// sandbox1
const incAll = () => {
console.log("set all counters");
incA();
incB();
};
// sandbox2
const incAll = () => {
setTimeout(() => {
console.log("set all counters");
incA();
incB();
}, 100);
};
console1:
render
set all counters
set counter
set counter
render
console2:
render
set all counters
set counter
render
set counter
render
What is the expected behavior?
Render function should be called once after multiple calls of setState
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
react: 16.7.0-alpha.2
tqwewe, Emanuele-Spatola, joalcava, tischsoic, art-in and 35 more
Metadata
Metadata
Assignees
Labels
No labels