Skip to content

Commit

Permalink
Merge pull request #1438 from jseminck/no-unsed-state-docs
Browse files Browse the repository at this point in the history
Add docs for no-unused-state
  • Loading branch information
ljharb committed Oct 18, 2017
2 parents 20ea1fb + 2525383 commit 773e0fe
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Finally, enable all of the rules that you would like to use. Use [our preset](#
* [react/no-unescaped-entities](docs/rules/no-unescaped-entities.md): Prevent invalid characters from appearing in markup
* [react/no-unknown-property](docs/rules/no-unknown-property.md): Prevent usage of unknown DOM property (fixable)
* [react/no-unused-prop-types](docs/rules/no-unused-prop-types.md): Prevent definitions of unused prop types
* [react/no-unused-state](docs/rules/no-unused-state.md): Prevent definitions of unused state properties
* [react/no-will-update-set-state](docs/rules/no-will-update-set-state.md): Prevent usage of `setState` in `componentWillUpdate`
* [react/prefer-es6-class](docs/rules/prefer-es6-class.md): Enforce ES5 or ES6 class for React Components
* [react/prefer-stateless-function](docs/rules/prefer-stateless-function.md): Enforce stateless React Components to be written as a pure function
Expand Down
45 changes: 45 additions & 0 deletions docs/rules/no-unused-state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Prevent definitions of unused state (react/no-unused-state)

Warns you if you have defined a property on the state, but it is not being used anywhere.

## Rule Details

The following patterns are considered warnings:

```jsx
class MyComponent extends React.Component {
state = { foo: 0 };
render() {
return <SomeComponent />;
}
}

var UnusedGetInitialStateTest = createReactClass({
getInitialState: function() {
return { foo: 0 };
},
render: function() {
return <SomeComponent />;
}
})
```

The following patterns are not considered warnings:

```jsx
class MyComponent extends React.Component {
state = { foo: 0 };
render() {
return <SomeComponent foo={this.state.foo} />;
}
}

var UnusedGetInitialStateTest = createReactClass({
getInitialState: function() {
return { foo: 0 };
},
render: function() {
return <SomeComponent foo={this.state.foo} />;
}
})
```

0 comments on commit 773e0fe

Please sign in to comment.