-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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 when a component is passed props that it doesn't need #2215
Comments
In that case, you wouldn't be able to pass custom attributes such as |
@RReverser like I said, this would need some sort of opt-in, which would not be used by components that take free-form props. |
@jussi-kalliokoski In that case, I think it can be implemented as external mixin or base class for those who need it. |
If you adhere to very simple rules this could very easily be solved statically/automatically in the future instead. That way everyone would benefit, regardless of whether you specify propTypes or not. Definitely not saying this shouldn't be done though, but that's where I would focus my effort if I would. |
Done: https://github.com/jussi-kalliokoski/react-mistyped-props (still missing the shape validation, but I'll probably add that later).
Which ones? ;)
That would be the perfect case and would give the fastest feedback, however...
... since static analysis is not exactly my forté, while I'm waiting for Flow (whose annotations I already started using, btw, since I feel happier reading code whose public functions are type-annotated :) or something similar to solve this problem among others, I made that mixin as a temporary solution. |
Merging this into #1587 which has more discussion. |
It would be cool to be able to get warnings for typoed or otherwise extraneous props passed to a component, similar to how
React.DOM
warns if you passclass
when you meantclassName
.With
PropTypes.shape
you could probably even ensure deep validity of the passed data. This would not only be useful for finding bugs, but also for optimizing hot components by making sure the shapes are aligned.Obviously this would need some sort of opt-in, like propTypes.
The text was updated successfully, but these errors were encountered: