> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# no-unused-state

[Added in v0.5.1](https://github.com/web-infra-dev/rslint/releases/tag/v0.5.1)
## Configuration


```ts title=rslint.config.ts
import { defineConfig, reactPlugin } from '@rslint/core';

export default defineConfig([
  reactPlugin.configs.recommended,
  {
    rules: {
      'react/no-unused-state': 'error',
    },
  },
]);
```

## Rule Details

Warns when a React component defines state fields that are never read anywhere in the component. State can be defined via constructor assignments (`this.state = {}`), class property declarations (`state = {}`), `this.setState()` calls, or `getInitialState()` returns in ES5 components.

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

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

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

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

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

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

## Original Documentation

- [eslint-plugin-react: no-unused-state](https://github.com/jsx-eslint/eslint-plugin-react/blob/v7.37.5/docs/rules/no-unused-state.md)
- [Source code](https://github.com/jsx-eslint/eslint-plugin-react/blob/v7.37.5/lib/rules/no-unused-state.js)
