Skip to content

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

@AlphaBeth

Description

@AlphaBeth

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions