False positive on `react/no-unused-prop-types`
See original GitHub issueI came across some code looking like this where myProp
was reportedly not being used, even though it was.
render() {
const { props } = this;
const { myProp } = props;
someFunction(myProp)
}
MyComponent.propTypes = {
myProp: PropTypes.number,
};
It seems the double desctructure confused the rule because a change to the code below fixed it.
render() {
const { myProp } = this.props;
someFunction(myProp)
}
I think it may be similar to https://github.com/yannickcr/eslint-plugin-react/issues/933, except this one is not such an anti-pattern. It looks very strange on my reduced version, but in a context with more variables can be more natural.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
eslint-plugin-react/no-unused-prop-types.md at master - GitHub
Disallow definitions of unused propTypes ( react/no-unused-prop-types ). Warns if a prop with a defined type isn't being used. Note: You can provide...
Read more >typescript-eslint/no-unused-vars false positive in type ...
And we have @typescript-eslint/no-unused-vars error in string with type declaration, which says 'name' is defined but never used.
Read more >Don't Call PropTypes Warning - React
bool . This pattern by itself is fine, but triggers a false positive because React thinks you are calling PropTypes directly. The next...
Read more >12 essential ESLint rules for React - LogRocket Blog
Requires that all React components have their props described in a PropTypes declaration. These checks only throw errors in development mode but ...
Read more >[Solved]-false positive in prop-types validation-Reactjs
You are not doing anything wrong. The problem is that every function that returns a JSX component is technically a stateless component.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello! Just showing my support for this bug to be fixed 😃 👍
I think destructuring props off of this is pretty rare, but i agree it should work.