-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Broken componentWill(Did)Update #2974
Comments
Your example correctly yields However, I'm pretty sure the issue you're seeing has to do with mutating objects in state/props. React does not clone objects passed in to state/props, hence, both |
Oh, yeah the problem occurs with objects, you are right, the example was not entirely complete. Anyway I do clone the object on assigning from props to component state either by doing |
Line 8, you're mutating the state object you try to compare. |
this.state.test.state = true;
this.setState({
test: this.state.test
}); Not sure why you need to manually set the state and then call setState - you should be able to do
|
As noted, you're modifying |
When updating state of the component the corresponding method from lifecycle get called but every time for any component the
prevState
ornextState
is in fact always the same with the current state. So comparing them always return true. Mentioned methods should return correct objects for previous, next state.The text was updated successfully, but these errors were encountered: