-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
react/no-unused-prop-types false positive on destructured props #1002
Comments
We have been encountering the same bug (on an SFC). |
Same problem :-( import React from 'react';
type User = {
country: string;
};
export default ({ user }: { user: User }) => (
<div>
{ user.country }
</div>
); 'user.country' PropType is defined but prop is never used (react/no-unused-prop-types) |
flow as well. Need a label. @ljharb I want to take a look into supporting flow soon. Gathering use cases. Thank you! |
first use case here is a known issue with the rule when using an intermediate variable to store props/parts of props. Second is fixed on master. |
Same if you use a prop by simple deconstructing like this: render({userId = 123}) {
...
} |
@derwaldgeist you can't use props like that; render takes no arguments. |
Yep, just found this out myself 👍 I was turning a stateless component in a class and missed this. |
I've adding support for this in #1393 which is still WIP. Will add these test cases but I'm quite sure they work already. |
react/no-unused-prop-types thinks that both the onClick and children props are unused even though these are clearly being used:
If I refer to onClick using this.props.onClick or destructure all the props from this.props it works.
The text was updated successfully, but these errors were encountered: