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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy