Skip to content

Commit 2525383

Browse files
author
Joachim Seminck
committed
Add docs for no-unused-state
1 parent 1f14fad commit 2525383

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Finally, enable all of the rules that you would like to use. Use [our preset](#
108108
* [react/no-unescaped-entities](docs/rules/no-unescaped-entities.md): Prevent invalid characters from appearing in markup
109109
* [react/no-unknown-property](docs/rules/no-unknown-property.md): Prevent usage of unknown DOM property (fixable)
110110
* [react/no-unused-prop-types](docs/rules/no-unused-prop-types.md): Prevent definitions of unused prop types
111+
* [react/no-unused-state](docs/rules/no-unused-state.md): Prevent definitions of unused state properties
111112
* [react/no-will-update-set-state](docs/rules/no-will-update-set-state.md): Prevent usage of `setState` in `componentWillUpdate`
112113
* [react/prefer-es6-class](docs/rules/prefer-es6-class.md): Enforce ES5 or ES6 class for React Components
113114
* [react/prefer-stateless-function](docs/rules/prefer-stateless-function.md): Enforce stateless React Components to be written as a pure function

docs/rules/no-unused-state.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Prevent definitions of unused state (react/no-unused-state)
2+
3+
Warns you if you have defined a property on the state, but it is not being used anywhere.
4+
5+
## Rule Details
6+
7+
The following patterns are considered warnings:
8+
9+
```jsx
10+
class MyComponent extends React.Component {
11+
state = { foo: 0 };
12+
render() {
13+
return <SomeComponent />;
14+
}
15+
}
16+
17+
var UnusedGetInitialStateTest = createReactClass({
18+
getInitialState: function() {
19+
return { foo: 0 };
20+
},
21+
render: function() {
22+
return <SomeComponent />;
23+
}
24+
})
25+
```
26+
27+
The following patterns are not considered warnings:
28+
29+
```jsx
30+
class MyComponent extends React.Component {
31+
state = { foo: 0 };
32+
render() {
33+
return <SomeComponent foo={this.state.foo} />;
34+
}
35+
}
36+
37+
var UnusedGetInitialStateTest = createReactClass({
38+
getInitialState: function() {
39+
return { foo: 0 };
40+
},
41+
render: function() {
42+
return <SomeComponent foo={this.state.foo} />;
43+
}
44+
})
45+
```

0 commit comments

Comments
 (0)