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 when a component is passed props that it doesn't need #2215

Closed
jussi-kalliokoski opened this issue Sep 19, 2014 · 6 comments
Closed

Warn when a component is passed props that it doesn't need #2215

jussi-kalliokoski opened this issue Sep 19, 2014 · 6 comments

Comments

@jussi-kalliokoski
Copy link

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 pass class when you meant className.

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.

@RReverser
Copy link
Contributor

In that case, you wouldn't be able to pass custom attributes such as data-*, aria-* for DOM (but can be any other names for custom components).

@jussi-kalliokoski
Copy link
Author

@RReverser like I said, this would need some sort of opt-in, which would not be used by components that take free-form props.

@RReverser
Copy link
Contributor

@jussi-kalliokoski In that case, I think it can be implemented as external mixin or base class for those who need it.

@syranide
Copy link
Contributor

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.

@jussi-kalliokoski
Copy link
Author

@RReverser

In that case, I think it can be implemented as external mixin or base class for those who need it.

Done: https://github.com/jussi-kalliokoski/react-mistyped-props (still missing the shape validation, but I'll probably add that later).

@syranide

If you adhere to very simple rules

Which ones? ;)

this could very easily be solved statically/automatically in the future instead.

That would be the perfect case and would give the fastest feedback, however...

but that's where I would focus my effort if I would.

... 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.

@zpao
Copy link
Member

zpao commented May 7, 2015

Merging this into #1587 which has more discussion.

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

No branches or pull requests

4 participants