---
title: "Rendered more hooks than during the previous render"
description: "React throws this when a component calls a different number of hooks from one render to the next. Learn why hook order matters and how to fix conditional hooks and early returns."
url: https://www.danny.engineering/answer/react/rendered-more-hooks-than-during-the-previous-render
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["React"]
---

# Rendered more hooks than during the previous render

## The short answer


A hook is being called conditionally, usually after an early `return` or inside an `if`. On one render React saw fewer hooks, on the next it saw more, and it cannot match them up. Move every hook call to the top of the component, above any early return, and put the condition inside the hook instead.


```diff
function Profile({ user }: { user: User | null }) {
-  if (!user) return <SignInPrompt />;
-  const [tab, setTab] = useState('posts');
+  const [tab, setTab] = useState('posts');
+  if (!user) return <SignInPrompt />;

   return <Tabs value={tab} onChange={setTab} />;
 }
```


## Why it happens


React does not store hook state by name. It keeps a list for each component and hands out the entries in order: the first `useState` call gets slot one, the next hook gets slot two, and so on. This only works if the component calls the same hooks in the same order on every render.


When a hook sits behind a condition, the list changes length. If the condition was false last time and true this time, React finds an extra hook it has no record of and throws "Rendered more hooks than during the previous render". The reverse case, where a hook is skipped, produces the related error "Rendered fewer hooks than expected. This may be caused by an accidental early return statement."


The usual causes are:

- An early `return` for a loading, error or empty state placed above a hook.
- A hook inside an `if`, a `switch` or a `&&` expression.
- A hook inside a loop whose length changes between renders.
- Calling a component as a plain function, such as `Row(props)` in a `.map`, so its hooks become part of the parent's list.

## How to fix it


### Call hooks first, return early afterwards


The most common fix is simply reordering. Put every hook at the top level of the component, then do the early returns.


```typescript
function Dashboard({ userId }: { userId: string | null }) {
  const [range, setRange] = useState('7d');
  const stats = useStats(userId, range);

  if (!userId) return <SignInPrompt />;
  if (!stats) return <Spinner />;

  return <StatsView stats={stats} range={range} onRangeChange={setRange} />;
}
```


### Move the condition inside the hook


If a hook should only do work in some cases, call it every time and let it decide. Most data and effect hooks accept a way to switch themselves off.


```typescript
useEffect(() => {
  if (!isOpen) return;
  const id = setInterval(refresh, 5000);
  return () => clearInterval(id);
}, [isOpen]);
```


For a custom hook, accept a nullable argument or an `enabled` flag rather than wrapping the call in an `if`.


### Split the conditional part into its own component


When a whole block of hooks only applies in one branch, move that branch into a child component. Each component has its own hook list, so rendering or not rendering the child is fine.


```typescript
function Profile({ user }: { user: User | null }) {
  if (!user) return <SignInPrompt />;
  return <SignedInProfile user={user} />;
}

function SignedInProfile({ user }: { user: User }) {
  const [tab, setTab] = useState('posts');
  const posts = usePosts(user.id);
  return <ProfileView tab={tab} onTabChange={setTab} posts={posts} />;
}
```


### Render components with JSX, not by calling them


If you call a component like a function, its hooks run inside the parent. Render it with JSX so React treats it as its own component.


```diff
- {rows.map((row) => Row({ row }))}
+ {rows.map((row) => <Row key={row.id} row={row} />)}
```


## Common pitfalls

- **Ignoring the lint rule.** The `react-hooks/rules-of-hooks` rule in `eslint-plugin-react-hooks` catches nearly every case of this before it reaches the browser. Turn it on as an error.
- **Thinking** **`use`** **is the exception for everything.** React 19's `use` API can be called inside conditions, but that does not apply to `useState`, `useEffect` or any other hook.
- **Hiding hooks in helpers.** A plain function that calls a hook is a hook too. Name it `useSomething` and follow the same rules so the linter can check it.
- **Fixing it with a key.** Adding a `key` to force a remount can hide the error but resets all state. Reorder the hooks instead.

## Related reading

- [React: Rules of Hooks](https://react.dev/reference/rules/rules-of-hooks)
- [React: Reusing logic with custom hooks](https://react.dev/learn/reusing-logic-with-custom-hooks)
