Skip to content

Invalid no-unused-prop-types catch #1506

Closed
@obrejla

Description

@obrejla

Hi,

Try this code:

import React from 'react';
import PropTypes from 'prop-types';

class Test extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            foo: false,
        };
    }

    onFoo() {
        this.setState((prevState, props) => {
            props.doSomething();
            return {
                foo: true,
            };
        });
    }

    render() {
        return (
            <div>{this.state.foo}</div>
        );
    }
}

Test.propTypes = {
    doSomething: PropTypes.func.isRequired,
};

export default Test;

You will get an error on line doSomething: PropTypes.func.isRequired, despite that doSomething is used inside the async version of setState(). Yep, I know, it's a strange usage, but it should be handled imho ;)

Thanks!

Activity

ljharb

ljharb commented on Oct 29, 2017

@ljharb
Member

Very strange usage; but yes, it should work.

added 5 commits that reference this issue on Oct 29, 2017
e9297da
5341fc5
cd5e34c
7ce1fe6
bf498a2
petersendidit

petersendidit commented on Oct 29, 2017

@petersendidit
Contributor

This is very similar to #1477 but fixable because the prop usage isn't in an arrow function that is an attribute to a JSX node. My research into fixing #1477 will work here.

added a commit that references this issue on Nov 5, 2017
c471d77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ljharb@petersendidit@obrejla

        Issue actions

          Invalid no-unused-prop-types catch · Issue #1506 · jsx-eslint/eslint-plugin-react