Fix guides · Lovable, Bolt, Cursor, Claude Code, v0 ·

Fix React "Rendered more hooks than during the previous render"

Error: Rendered more hooks than during the previous render.

React tracks hooks by their order. This error means a component called more hooks on this render than on the last one, almost always because a hook sits after an early return (if (loading) return …) or inside an if, loop or callback. Move every hook to the top of the component, before any return.

Free · 3 a day · no signup

Common causes – and how to tell which one you have

1. A hook is below an early return

How to tell: The component has if (loading) return …, if (!user) return null or similar, and a useState/useEffect/useMemo further down. The error appears when loading finishes.

Fix: Move all hooks above the first return. The early return can stay, just below the hooks.

2. A hook is inside a condition

How to tell: Code like if (user) { useEffect(…) } or isOpen && useSomething().

Fix: Call the hook every time and move the condition inside it: useEffect(() => { if (!user) return; … }, [user]).

3. A data-fetching hook only runs sometimes

How to tell: useQuery, useSWR or a custom useFetch is called only when an id exists, e.g. const data = id ? useQuery(…) : null.

Fix: Always call it and disable it instead: useQuery({ queryKey: ['item', id], queryFn, enabled: !!id }) or useSWR(id ? key : null, fetcher).

4. Hooks inside a loop or .map()

How to tell: Something like items.map((item) => { const [open, setOpen] = useState(false); … }) inside the parent component.

Fix: Move the item into its own component (<Item item={item} />) and call the hook inside that component.

5. A component is called as a function

How to tell: A child component that uses hooks is called like {renderRow(item)} or {Row(props)} only for some rows.

Fix: Render it as JSX (<Row {...props} />) so its hooks belong to its own component.

How to fix it

  1. Open the component named in the stack trace.
  2. Look for any return before the last hook call, such as if (loading) return <Spinner />.
  3. Move all hook calls above the first return in the component.
  4. Look for hooks inside if, &&, ternaries, loops, .map() or try/catch, and move them to the top level.
  5. Put the condition inside the hook instead, e.g. useEffect(() => { if (!user) return; … }, [user]) or useQuery({ enabled: !!user }).
  6. Install or enable eslint-plugin-react-hooks so the rule is checked in your editor.
  7. Reload the page and repeat the action that triggered the error.

Using Lovable, Bolt or v0?

In Lovable, Bolt or v0, paste the full error and say: "Move all hooks in this component above every early return and out of conditions. Don't change what the component renders."

Using Cursor, Claude Code or Windsurf?

Ask Cursor or Claude Code to find the component from the stack trace and list every hook with its line number and any return or condition above it. Have it enable the react-hooks ESLint rules so this is flagged next time.

The “fix” to avoid

Agents sometimes wrap the component in an error boundary, add a key to force remounting, or turn the component into a class. That hides the symptom. The fix is simply to call the same hooks in the same order on every render.

Copy-paste fix prompt for your AI coding tool

Paste this into Cursor, Claude Code, Lovable or Bolt:

My React app throws "Rendered more hooks than during the previous render". Find the component from the stack trace. Move every hook call (useState, useEffect, useMemo, useCallback, useContext, data-fetching hooks and custom useX hooks) to the top level of the component, above any early return. Remove hooks from conditions, loops and callbacks; put the condition inside the hook instead (if inside useEffect, enabled option for queries). Keep the rendering logic the same. Show me which hook was conditional and the fixed component.
Your error looks a bit different? Paste your exact error and get a diagnosis tailored to your code — free.

Questions people ask

What about "Rendered fewer hooks than expected"?

Same cause in the other direction: an early return now skips hooks that ran last time. The fix is the same: hooks first, returns after.

Why did it only break after loading finished?

On the first render the early return (loading) ran before the hook. Once data arrived, the hook ran too, so React saw one more hook than before.

Can I call a hook inside useEffect?

No. Call the hook at the top of the component and use its value inside the effect.

Official documentation

Related errors

Get fixes like this every week