Skip to content

Commit e911882

Browse files
coryhouseljharb
authored andcommitted
[docs] no-unused-prop-types: clean up prose
1 parent c739c9e commit e911882

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

docs/rules/no-unused-prop-types.md

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,49 @@
1-
# Prevent definitions of unused prop types (react/no-unused-prop-types)
1+
# Prevent definitions of unused propTypes (react/no-unused-prop-types)
22

3-
Warns you if you have defined a prop type but it is never being used anywhere.
3+
Warns if a propType isn't being used.
44

55
## Rule Details
66

77
The following patterns are considered warnings:
88

99
```jsx
10-
var Hello = createReactClass({
11-
propTypes: {
12-
name: PropTypes.string
13-
},
14-
render: function() {
10+
class Hello extends React.Component {
11+
render() {
1512
return <div>Hello Bob</div>;
1613
}
1714
});
1815

19-
var Hello = createReactClass({
20-
propTypes: {
21-
firstname: PropTypes.string.isRequired,
22-
middlename: PropTypes.string.isRequired, // middlename is never used below
23-
lastname: PropTypes.string.isRequired
24-
},
25-
render: function() {
16+
Hello.propTypes = {
17+
name: PropTypes.string
18+
},
19+
```
20+
21+
```jsx
22+
class Hello extends React.Component {
23+
render() {
2624
return <div>Hello {this.props.firstname} {this.props.lastname}</div>;
2725
}
28-
});
26+
}
27+
28+
Hello.propTypes: {
29+
firstname: PropTypes.string.isRequired,
30+
middlename: PropTypes.string.isRequired, // middlename is never used above
31+
lastname: PropTypes.string.isRequired
32+
},
2933
```
3034

3135
The following patterns are **not** considered warnings:
3236

3337
```jsx
34-
var Hello = createReactClass({
35-
propTypes: {
36-
name: PropTypes.string
37-
},
38-
render: function() {
38+
class Hello extends React.Component {
39+
render() {
3940
return <div>Hello {this.props.name}</div>;
4041
}
41-
});
42+
};
43+
44+
Hello.propTypes: {
45+
name: PropTypes.string
46+
},
4247
```
4348

4449
## Rule Options
@@ -59,12 +64,13 @@ This rule can take one argument to ignore some specific props during validation.
5964

6065
- [False Positives: SFC (helper render methods)](#false-positives-sfc)
6166

62-
### False positives SFC
63-
For components with Stateless Functional Components (often used as helper render methods);
64-
SFC is a function that takes prop(s) as an argument and returns a JSX expression.
65-
Even if this function gets called from a component the props that are only used inside SFC would not be considered used by a component.
67+
### False Positives SFC
68+
69+
Stateless Function Components (SFCs) accept props as an argument and return a JSX expression.
70+
Even if the function gets called from a component, the props that are only used inside the component are not be considered used by a component.
6671

6772
Triggers false positive:
73+
6874
```js
6975
function AComponent(props) {
7076
function helperRenderer(aProp) { // is considered SFC

0 commit comments

Comments
 (0)