eslint-plugin-react: v7.12.0 update throw is missing in props validation (react/prop-types)

After updating to v7.12.0 appeared strange validation errors.

I have this propTypes:

propTypes = {
    actions: PropTypes.object.isRequired,
};

and this code:

componentWillReceiveProps (nextProps) {
    this.props.actions.doSomething();
}

componentWillUnmount () {
    this.props.actions.doSomething();
}

And then I have eslint error: ‘doSomething’ is missing in props validation react/prop-type on the line in componentWillReceiveProps. But the line in componentWillUnmount is ok. Strange that it says “‘doSomething’ is missing” and not “‘actions.doSomething’ is missing”

I tried to change “PropTypes.object” to “PropTypes.shape”, still the same.

Error disappears if I change name “componentWillReceiveProps” to something else. If I add propType “doSomething: PropTypes.func.isRequired” error disappears too but it doesn’t make sense.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 12
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Now that is a bug - accessing things chained off of this.props should error, but not things off of this.

cc @alexzherdev

v7.12.1 is released.

Thanks everybody; if you have different code that’s erroring, please post it. If you’re just experiencing the same issue, please add an emoji reaction to the original post.

This is an accepted bug; we just need someone to work on it.

Similar issue when we have Ref element like this:

componentDidUpdate() { this.inputRef.focus(); }

error ‘focus’ is missing in props validation react/prop-types

Update: Also other standard methods like Array.findIndex, Array.length throw this error.

Hi, also this code throw a error after upgrading to 7.12

componentDidUpdate() {
...
        const {
            first_organization,
            second_organization,
        } = this.state;
...
155:13  error  'state.first_organization' is missing in props validation   react/prop-types
156:13  error  'state.second_organization' is missing in props validation  react/prop-types

Thank you for your work.