Eslint-plugin-react: Invalid no-unused-prop-types catch

Created on 28 Oct 2017  路  2Comments  路  Source: yannickcr/eslint-plugin-react

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!

bug help wanted

All 2 comments

Very strange usage; but yes, it should work.

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.

Was this page helpful?
0 / 5 - 0 ratings