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

react/no-unused-prop-types when use props in nested function in functional component #1234

Closed
AlphaBeth opened this issue Jun 1, 2017 · 2 comments

Comments

@AlphaBeth
Copy link

This code

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

function TestComponent(props) {
    function getA() {
        return props.a;
    }
    function getB() {
        return props.b;
    }
    function getCD() {
        return props.c + props.d;
    }
    return (<div>
        {getA()}
        {getB()}
        {getCD()}
    </div>);
}

TestComponent.propTypes = {
    a: PropTypes.string.isRequired,
    b: PropTypes.string.isRequired,
    c: PropTypes.string.isRequired,
    d: PropTypes.string.isRequired,
};

export default TestComponent;

will raise errors

  22:8  error  'a' PropType is defined but prop is never used  react/no-unused-prop-types
  23:8  error  'b' PropType is defined but prop is never used  react/no-unused-prop-types

for all props except used in last function.

@ljharb
Copy link
Member

ljharb commented Jun 1, 2017

This should certainly be fixed; but you may want instead to destructure the props in the signature, which would avoid this problem.

@jseminck
Copy link
Contributor

jseminck commented Jun 1, 2017

This was fixed by: #1218

To confirm, I ran your exact test-case on master and it now passes as valid!

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

No branches or pull requests

3 participants