# rules-of-hooks

Rule `react-hooks/rules-of-hooks`. Enforces the Rules of Hooks

- Source: react-hooks
- Technologies: React
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 201.1M weekly downloads of presets that enable it
- Trend: +35.3% last quarter
- Rank: #77 by reach, #1064 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `react-hooks/rules-of-hooks` | yes | no | package `eslint-plugin-react-hooks` | [docs](https://react.dev/reference/eslint-plugin-react-hooks/lints/rules-of-hooks) |
| Oxlint | `react/rules-of-hooks` | no | no | plugin `react`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/react/rules-of-hooks.html) |
| Biome | `correctness/useHookAtTopLevel` | yes | no | group correctness, since 1.0.0 | [docs](https://biomejs.dev/linter/rules/use-hook-at-top-level/) |

## Code examples

### Incorrect: the rule reports this

```js
if (isLoggedIn) {
  const [user, setUser] = useState(null);
}
```

```js
if (!data) return <Loading />;
const [processed, setProcessed] = useState(data);
```

```js
<button onClick={() => {
  const [clicked, setClicked] = useState(false);
}}/>
```

### Correct: the rule accepts this

```js
if (shouldFetch) {
  const data = use(fetchPromise);
}
```

```js
for (const promise of promises) {
  results.push(use(promise));
}
```

```js
const [count, setCount] = useState(0);
const [name, setName] = useState('');

if (!isSpecial) {
  return null;
}

if (shouldFetch) {
```

Examples from the ESLint documentation.

## Enable it

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

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

export default [
  {
    plugins: { "react-hooks": reactHooks },
    rules: {
      "react-hooks/rules-of-hooks": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "react"
  ],
  "rules": {
    "react/rules-of-hooks": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "correctness": {
        "useHookAtTopLevel": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [React Hooks recommended](https://lintradar.dev/presets/react-hooks-recommended.md) | ESLint | `eslint-plugin-react-hooks` | 16 | 118.4M | +21.5% |
| [Next.js Core Web Vitals](https://lintradar.dev/presets/next-core-web-vitals.md) | ESLint | `eslint-config-next` | 62 | 46.8M | +48.8% |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [Create React App](https://lintradar.dev/presets/react-app.md) | ESLint | `eslint-config-react-app` | 109 | 4.1M | +4.3% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [React Native](https://lintradar.dev/presets/react-native.md) | ESLint | `@react-native/eslint-config` | 79 | 1.2M | +5.8% |

## Related rules

- [react-hooks/exhaustive-deps](https://lintradar.dev/rules/react-hooks/exhaustive-deps.md): Verifies the list of dependencies for Hooks like useEffect and similar
- [react-hooks/error-boundaries](https://lintradar.dev/rules/react-hooks/error-boundaries.md): Validates usage of error boundaries instead of try/catch for errors in child components
- [react-hooks/globals](https://lintradar.dev/rules/react-hooks/globals.md): Validates against assignment/mutation of globals during render, part of ensuring that side effects must render outside of render
- [react-hooks/immutability](https://lintradar.dev/rules/react-hooks/immutability.md): Validates against mutating props, state, and other values that are immutable
- [react-hooks/incompatible-library](https://lintradar.dev/rules/react-hooks/incompatible-library.md): Validates against usage of libraries which are incompatible with memoization (manual or automatic)
- [react-hooks/preserve-manual-memoization](https://lintradar.dev/rules/react-hooks/preserve-manual-memoization.md): Validates that existing manual memoized is preserved by the compiler. React Compiler will only compile components and hooks if its inference matches or exceeds the existing manual memoization

---

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