---
title: rules-of-hooks
---
Validates that components and hooks follow the [Rules of Hooks](/reference/rules/rules-of-hooks).
## Rule Details {/*rule-details*/}
React relies on the order in which hooks are called to correctly preserve state between renders. Each time your component renders, React expects the exact same hooks to be called in the exact same order. When hooks are called conditionally or in loops, React loses track of which state corresponds to which hook call, leading to bugs like state mismatches and "Rendered fewer/more hooks than expected" errors.
## Common Violations {/*common-violations*/}
These patterns violate the Rules of Hooks:
- **Hooks in conditions** (`if`/`else`, ternary, `&&`/`||`)
- **Hooks in loops** (`for`, `while`, `do-while`)
- **Hooks after early returns**
- **Hooks in callbacks/event handlers**
- **Hooks in async functions**
- **Hooks in class methods**
- **Hooks at module level**
### `use` hook {/*use-hook*/}
The `use` hook is different from other React hooks. You can call it conditionally and in loops:
```js
// ✅ `use` can be conditional
if (shouldFetch) {
const data = use(fetchPromise);
}
// ✅ `use` can be in loops
for (const promise of promises) {
results.push(use(promise));
}
```
However, `use` still has restrictions:
- Can't be wrapped in try/catch
- Must be called inside a component or hook
Learn more: [`use` API Reference](/reference/react/use)
### Invalid {/*invalid*/}
Examples of incorrect code for this rule:
```js
// ❌ Hook in condition
if (isLoggedIn) {
const [user, setUser] = useState(null);
}
// ❌ Hook after early return
if (!data) return ;
const [processed, setProcessed] = useState(data);
// ❌ Hook in callback