Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for no-unused-state #1438

Merged
merged 1 commit into from Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
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
@@ -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} />;
}
})
```