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

Destructuring values from this.<anything> in componentDidUpdate causes prop-types errors #2017

Closed
ThiefMaster opened this issue Oct 16, 2018 · 3 comments
Labels

Comments

@ThiefMaster
Copy link
Contributor

Note: This only happens with master, not with the latest stable release.

error 'state.bar' is missing in props validation react/prop-types

Example code:

class Test extends React.Component {
    componentDidUpdate() {
        const {bar} = this.state;
        console.log(bar);
    }

    render() {
        return null;
    }
}
$ npx eslint test.js

/home/adrian/dev/indico/src/test.js
  1:1   error  This module could be parsed as a valid script  import/unambiguous
  1:7   error  'Test' is defined but never used               no-unused-vars
  1:20  error  'React' is not defined                         no-undef
  3:16  error  'state.bar' is missing in props validation     react/prop-types

✖ 4 problems (4 errors, 0 warnings)

Disregard the first three errors; I just couldn't be bothered to add the imports etc to the test file - the 4th error is not related to those.

@ThiefMaster ThiefMaster changed the title Destructuring values from this.state in componentDidUpdate causes prop-types errors Destructuring values from this.<anything> in componentDidUpdate causes prop-types errors Oct 16, 2018
@ThiefMaster
Copy link
Contributor Author

ThiefMaster commented Oct 16, 2018

Looking at the code this happens in any lifecycle method, regardless of what this. attribute is destructured. I guess the check in isPropTypesUsage is too broad since it doesn't look at the name of the attribute that's destructured in case of a lifecycle method.

@ljharb
Copy link
Member

ljharb commented Oct 16, 2018

cc @alexzherdev

@alexzherdev
Copy link
Contributor

Oh 😞 I'll take a look

@ljharb ljharb closed this as completed in 67989c8 Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants