# no-did-mount-set-state

Rule `react/no-did-mount-set-state`. Disallow usage of setState in componentDidMount

- Source: react
- Technologies: React
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 1.2M weekly downloads of presets that enable it
- Trend: +5.8% last quarter
- Rank: #1566 by reach, #1484 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```jsx
var Hello = createReactClass({
  componentDidMount: function() {
    this.setState({
      name: this.props.name.toUpperCase()
    });
  },
  render: function() {
    return <div>Hello {this.state.name}</div>;
  }
});
```

### Correct: the rule accepts this

```jsx
var Hello = createReactClass({
  componentDidMount: function() {
    this.onMount(function callback(newName) {
      this.setState({
        name: newName
      });
    });
  },
  render: function() {
    return <div>Hello {this.state.name}</div>;
  }
});
```

```jsx
var Hello = createReactClass({
  componentDidMount: function() {
    this.props.onMount();
  },
  render: function() {
    return <div>Hello {this.props.name}</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/no-did-mount-set-state": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "react"
  ],
  "rules": {
    "react/no-did-mount-set-state": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [React Native](https://lintradar.dev/presets/react-native.md) | ESLint | `@react-native/eslint-config` | 79 | 1.2M | +5.8% |

## Related rules

- [react/jsx-props-no-spread-multi](https://lintradar.dev/rules/react/jsx-props-no-spread-multi.md): Disallow JSX prop spreading the same identifier multiple times
- [react/forbid-elements](https://lintradar.dev/rules/react/forbid-elements.md): Disallow certain elements
- [react/iframe-missing-sandbox](https://lintradar.dev/rules/react/iframe-missing-sandbox.md): Enforce sandbox attribute on iframe elements
- [react/no-unsafe](https://lintradar.dev/rules/react/no-unsafe.md): Disallow usage of unsafe lifecycle methods
- [react/jsx-no-literals](https://lintradar.dev/rules/react/jsx-no-literals.md): Disallow usage of string literals in JSX
- [react/sort-comp](https://lintradar.dev/rules/react/sort-comp.md): Enforce component methods order

---

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