Skip to content

Destructuring props in a stateful component triggers 'react/no-unused-prop-types' with flow in nested components #1335

Closed
@karl-run

Description

When accessing the props directly, through this.props.foo.bar it works as expected, but if I destructure foo const { foo } = this.props and then access bar through it, it is still not registered as used and will be flagged with react/no-unused-prop-types.

Full example:

type Props = {
  foo: {
    bar: boolean, // error  'foo.bar' PropType is defined but prop is never used
  },
};

class DigitalServices extends React.Component {
  props: Props

  render() {
    const { foo } = this.props;

    return <div>{foo.bar}</div>;
  }
}

This works as expected:

class DigitalServices extends React.Component {
  props: Props

  render() {
    return <div>{this.props.foo.bar}</div>;
  }
}

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