[15.6.2] setState callback does not fire
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
I have the following piece of code in my fairly simple component:
this.setState({ value: nextValue }, callback);
It works perfectly in React 16, but not in 15.6.2. On 15.6.2, callback does not fire. I investigated and saw this in react.development.js:
this.updater.enqueueSetState(this, partialState, callback, 'setState');
which clearly marks callback as one of the accepted arguments of enqueueSetState. However, when we go to the function that’s being called, in ReactUpdateQueue.js:
enqueueSetState: function (publicInstance, partialState) {
now we see this argument is ommited. I don’t know if that helps, anyway, the callback is not fired whatever I try to do.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
Here’s a simple example for reproduction: https://codesandbox.io/s/2kz06l3p0
What is the expected behavior?
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 15.6.1, 15.6.2 (not tested other 15.x) NOT React 16.x
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (1 by maintainers)
I honestly have my mind blown. When I change the minimal reproduction ( https://codesandbox.io/s/2kz06l3p0 ) so that I copy the whole Calendar.jsx, straight from the newest version into the same code here, it all works ( https://codesandbox.io/s/ko3n899jr3 )
There is a difference though! When I call this.setState, the same very line, now this.setState is calling a different function!
Here’s the setState in the first example that DID NOT work:
Here’s the setState in the second example that DID work:
Hmm… After all, it looks like actually there are two different versions of react and somehow react-calendar library has its own version imported…? 😨
Yes. Just make sure that you have matching react and react-dom versions installed, and that your dependency is not misconfigured to require a different, specific react version on its own.