Skip to content
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

Warn if people pass in "mutated" props #5335

Closed
jimfb opened this issue Oct 30, 2015 · 2 comments · Fixed by #5346
Closed

Warn if people pass in "mutated" props #5335

jimfb opened this issue Oct 30, 2015 · 2 comments · Fixed by #5346

Comments

@jimfb
Copy link
Contributor

jimfb commented Oct 30, 2015

Having the constructor passing super a props object that differs (in object equality and/or shallow compare) from the original is... illegal, because: #5334

We should have a warning for that, because it's reasonable for someone to assume they could extend a component and modify the props, without considering the ramifications, and the bug won't show up in their initial render test but will show up when the component updates.

@ManasJayanth
Copy link
Contributor

@jimfb Can a shallow comparison of inst.props and publicProps suffice, or is a deep equality check between the two objects needed?

@jimfb
Copy link
Contributor Author

jimfb commented Oct 30, 2015

I think shallow is fine. Deep equality is too difficult/expensive because of cycles.

Note that we should only do the check in dev mode, so surround your logic with a if(__DEV__) block

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants