The Prompt BakeryTemplates and prompts

Fix · Pages, phones and Arabic

React: Invalid hook call

What you may see

  • The console says hooks can only be called inside a function component

Most likely cause

A hook is used outside a component, inside a condition or loop, or two copies of React are installed.

Check first (about two minutes)

  1. Run npm ls react: is there more than one version?

The fix prompt

What you type here never leaves your browser. The search runs on this page, and nothing is sent to a server or to an AI.

Kept only in this browser, on this device. Keys and passwords are removed before anything is saved.

Prompt language

Paste it into Claude, ChatGPT, Gemini or Cursor, then follow what it says.

After you tried it, did it work?

Steps

  1. Show the component and where the hook is called.
  2. Move hooks to the top of function components, never inside if or loops.
  3. If two copies of React exist, align versions so only one is installed.

Do not do this

  • Do not install React twice.
  • Do not turn components into classes to avoid it.

Related

Try another entry

How can we help?

What do you need?
Your email, so we can reply (optional)Only enter your own email. We reply there.