Skip to content

react/no-unused-proptype false positive #1183

Closed
@georeith

Description

The following is considered an error for the props a and b:

import React from 'react';

export default function SomeComponent(props) {
    const callback = () => {
        props.a(props.b);
    };

    const anotherCallback = () => {};

    return (
        <SomeOtherComponent
            name={props.c}
            callback={callback}
        />
    );
}

SomeComponent.propTypes = {
    a: React.PropTypes.func.isRequired,
    b: React.PropTypes.string.isRequired,
    c: React.PropTypes.string.isRequired,
};

Removing the line const anotherCallback = () => {}; fixes the false positive.
The following does not trigger an error:

import React from 'react';

export default function SomeComponent(props) {
    const callback = () => {
        props.a(props.b);
    };

    return (
        <SomeOtherComponent
            name={props.c}
            callback={callback}
        />
    );
}

SomeComponent.propTypes = {
    a: React.PropTypes.func.isRequired,
    b: React.PropTypes.string.isRequired,
    c: React.PropTypes.string.isRequired,
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions