-
Notifications
You must be signed in to change notification settings - Fork 48.5k
Warn on direct state manipulation (#2272) #8265
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
Conversation
…f this.setState(). Fixes facebook#2272.
Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours has expired. Before we can review or merge your code, we need you to email [email protected] with your details so we can update your status. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
shallowEqual(this._currentState, inst.state), | ||
'this.state: Setting state directly with this.state is not ' + | ||
'recommended. Instead, use this.setState().' | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how useful this warning would really be, it doesn't give you any information about what was mutated or where it happened. I know that providing those details would make this more difficult, but I don't think it provides a whole lot of benefit for the cost as it stands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. Adding the name of the component to the warning is relatively easy. I should have done that in the first place. Showing what was changed is definitely more difficult. If people think that's valuable then I'm willing to look into it.
@iansu were you still working on this? |
@oksas I'd like to continue working on this. I have some ideas to improve the implementation, it's just unclear if those improvements will be enough to justify including this feature. Also, for some reason I didn't get a notification that @gaearon mentioned this pull request. 😞 Possible improvements:
|
…y of the current state when running in dev mode. facebook#2272
@iansu can you resolve the merge conflicts? This LGTM, I think we can move forward with it once its mergeable. |
Done. Just waiting for the tests to run on CI now. |
@aweary this is done now. Not sure if you saw my previous message because I didn't explicitly mention you. |
@iansu thanks! Can you run the |
@aweary done! Looks like a couple of tests might be failing because of my changes. I'm not too familiar with Fiber though. Let me know if I should try and fix them. |
@aweary @gaearon sounds good. Is there any documentation on running the Fiber tests? The "How to Contribute" page just says to run |
@iansu: Sorry for chiming in late, but you can run tests against Fiber using the That said, I think we actually want to pass on this change. Even though we warn if So I'm going to close this PR. Sorry for the inconvenience! And thanks a ton for the time and effort you spent on it. 🙇 |
@bvaughn Well that's disappointing but I appreciate the explanation. I'll keep looking for other opportunities to contribute. 😀 |
Adds a warning when setting state directly using this.state instead of this.setState().
Resolves #2272