# state-in-constructor

Rule `react/state-in-constructor`. Enforce class component state initialization style

- Source: react
- Technologies: React
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 3.4M weekly downloads of presets that enable it
- Trend: +2.3% last quarter
- Rank: #1431 by reach, #1567 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `react/state-in-constructor` | no | no | package `eslint-plugin-react` | [docs](https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/state-in-constructor.md) |
| Oxlint | `react/state-in-constructor` | no | no | plugin `react`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/react/state-in-constructor.html) |

## Code examples

### Incorrect: the rule reports this

```jsx
class Foo extends React.Component {
  state = { bar: 0 }
  render() {
    return <div>Foo</div>
  }
}
```

```jsx
class Foo extends React.Component {
  constructor(props) {
    super(props)
    this.state = { bar: 0 }
  }
  render() {
    return <div>Foo</div>
  }
}
```

### Correct: the rule accepts this

```jsx
class Foo extends React.Component {
  constructor(props) {
    super(props)
    this.state = { bar: 0 }
  }
  render() {
    return <div>Foo</div>
  }
}
```

```jsx
class Foo extends React.Component {
  state = { bar: 0 }
  render() {
    return <div>Foo</div>
  }
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import react from "eslint-plugin-react";

export default [
  {
    plugins: { react },
    rules: {
      "react/state-in-constructor": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "react"
  ],
  "rules": {
    "react/state-in-constructor": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Airbnb](https://lintradar.dev/presets/airbnb.md) | ESLint | `eslint-config-airbnb` | 346 | 3.4M | +2.3% |

## Related rules

- [react/no-will-update-set-state](https://lintradar.dev/rules/react/no-will-update-set-state.md): Disallow usage of setState in componentWillUpdate
- [react/jsx-props-no-spreading](https://lintradar.dev/rules/react/jsx-props-no-spreading.md): Disallow JSX prop spreading
- [react/default-props-match-prop-types](https://lintradar.dev/rules/react/default-props-match-prop-types.md): Enforce all defaultProps have a corresponding non-required PropType
- [react/destructuring-assignment](https://lintradar.dev/rules/react/destructuring-assignment.md): Enforce consistent usage of destructuring assignment of props, state, and context
- [react/jsx-boolean-value](https://lintradar.dev/rules/react/jsx-boolean-value.md): Enforce boolean attributes notation in JSX
- [react/forbid-prop-types](https://lintradar.dev/rules/react/forbid-prop-types.md): Disallow certain propTypes

---

Web page: https://lintradar.dev/rules/react/state-in-constructor. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
