question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

False positive on `react/no-unused-prop-types`

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
philip-petersoncommented, Nov 8, 2018

Hello! Just showing my support for this bug to be fixed 😃 👍

2reactions
ljharbcommented, Apr 11, 2018

I think destructuring props off of this is pretty rare, but i agree it should work.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found