-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
setState callback is not called (React 16?) #953
Comments
Enzyme is not currently compatible with react 16 alpha, which also means it's not compatible with a version of RN that requires it. |
@rroehrig Update your react-test-renderer as well to @16.0.0-alpha.6 and see if the issue still exists. |
@AlbertBrand Thanks for the hint! I tried to update this dependency as well but it's still not working. |
Ah, makes sense as you are using Enzyme. I had the same issue but I'm only using the test renderer via Jest. Enzyme probably has its own implementation. |
I'm hitting this issue as well but I'm not using enzyme, just |
I think I have found the issue. Updater.prototype.enqueueSetState = function enqueueSetState(publicInstance, partialState, callback, callerName) {
if (typeof partialState === 'function') {
partialState = partialState(publicInstance.state, publicInstance.props);
}
this._renderer._newState = _extends({}, publicInstance.state, partialState);
this._renderer.render(this._renderer._element, this._renderer._context);
}; As you can see, the enqueueSetState: function (instance, partialState, callback) {
var fiber = ReactInstanceMap_1.get(instance);
var priorityLevel = getPriorityContext(fiber, false);
callback = callback === undefined ? null : callback;
{
warnOnInvalidCallback(callback, 'setState');
}
addUpdate$1(fiber, partialState, callback, priorityLevel);
scheduleUpdate(fiber, priorityLevel);
} where the UPDATE: It works! Use the following instead of the shallow renderer, and the import renderer from 'react-test-renderer'
const deepInstance = renderer.create(<YourComponent />).getInstance() |
No solution with enzyme? Using |
with:
it doesn't work, setState callback is somehow ignored |
@StefanoSega thanks, would you mind filing a new issue about that? |
In short:
When testing a component which depends on the
callback
ofsetState(updater, callback)
, it's not working since our last react-native/react upgrade.In detail:
Since the last react-native upgrade (which comes with react 16 alpha), a test is failing which previously worked. I report this issue here because the production code works.
setState(updater, callback)
has been changed in react 16, so I assume some enzyme "glue code" does not work anymore.I've created a snippet which shows the problem:
Relevant dependencies:
Thank you in advance!
The text was updated successfully, but these errors were encountered: