Skip to content

Commit

Permalink
[Docs] no-unused-prop-types: Add new example to rule
Browse files Browse the repository at this point in the history
Fixes #2849
  • Loading branch information
Hereward Mills authored and ljharb committed Nov 8, 2020
1 parent 796b609 commit 5708ecf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -22,13 +22,17 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
* [`prop-types`]: default argument does not count as props-types declaration ([#2877][] @golopot)
* [`jsx-props-no-multi-spaces`]: fix a false positive for beside comments ([#2878][] @golopot)

### Docs
* [`no-unused-prop-types`]: Add new example to rule ([#2852][] @thehereward)

[#2879]: https://github.com/yannickcr/eslint-plugin-react/issues/2879
[#2878]: https://github.com/yannickcr/eslint-plugin-react/pull/2878
[#2877]: https://github.com/yannickcr/eslint-plugin-react/pull/2877
[#2875]: https://github.com/yannickcr/eslint-plugin-react/issues/2875
[#2871]: https://github.com/yannickcr/eslint-plugin-react/issues/2871
[#2870]: https://github.com/yannickcr/eslint-plugin-react/issues/2870
[#2869]: https://github.com/yannickcr/eslint-plugin-react/issues/2869
[#2852]: https://github.com/yannickcr/eslint-plugin-react/pull/2852
[#2851]: https://github.com/yannickcr/eslint-plugin-react/issues/2851
[#2843]: https://github.com/yannickcr/eslint-plugin-react/pull/2843
[#2840]: https://github.com/yannickcr/eslint-plugin-react/issues/2840
Expand Down
21 changes: 20 additions & 1 deletion docs/rules/no-unused-prop-types.md
Expand Up @@ -25,7 +25,7 @@ Hello.propTypes = {
```jsx
type Props = {
firstname: string,
middlename: string, // middlename is never used above
middlename: string, // middlename is never used by the Hello component
lastname: string
}

Expand All @@ -36,6 +36,25 @@ class Hello extends React.Component<Props> {
}
```

```jsx
type Props = {
firstname: string;
lastname: string; // lastname isn't used by the Hello component
};

class Hello extends React.Component<Props> {
render() {
return <div>Hello {this.props.firstname}</div>;
}
}

class Greetings extends React.Component<Props> {
render() {
return <div>Greetings {this.props.firstname} {this.props.lastname}</div>;
}
}
```

Examples of **correct** code for this rule:

```jsx
Expand Down

0 comments on commit 5708ecf

Please sign in to comment.