Skip to content

Referencing with PropTypes.shape #833

Closed
@vutran

Description

@vutran

When referencing shaped PropTypes, it is producing react/no-unused-prop-types.

See below:

const myComponent = ({ bar }) => (
  <div>
    {bar.a}
    {bar.n}
    {bar.c}
  </div>
);

myComponent.propTypes = {
  bar: PropTypes.shape({
    a: PropTypes.string, // react-no-unused-prop-types
    b: PropTypes.string, // react-no-unused-prop-types
    c: PropTypes.string, // react-no-unused-prop-types
  }),
};

Also errors for:

const myComponent = (props) => {
  const bar = props.bar; // produces errors
  // const { bar } = props; // produce errors
  return (
    <div>
      {bar.a}
      {bar.n}
      {bar.c}
    </div>
  );
}

We would have to use it directly to avoid errors:

const myComponent = (props) => {
  return (
    <div>
      {props.bar.a}
      {props.bar.n}
      {props.bar.c}
    </div>
  );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions