React rules broken · Usually quick to fix
Invalid hook call
A React hook is being used incorrectly. It’s probably called inside a condition, loop, or regular function instead of at the top of a component.
What the error looks like
Invalid hook call. Hooks can only be called inside of the body of a function component.
Why it happens
React hooks (useState, useEffect, etc.) must be called at the top level of a component, not inside if statements, loops, or helper functions.
How to fix it
- Move all hook calls to the top of your component function
- Don’t put hooks inside if/else blocks or loops
- Make sure you’re not calling hooks from a regular function, only from React components or custom hooks
Ask your AI coding tool to fix it
Paste this prompt into Claude Code, Cursor, Bolt or Lovable, with your own error in place of the example.
I'm getting this error and I need help understanding and fixing it:
```
Invalid hook call. Hooks can only be called inside of the body of a function component.
```
Please:
1. Explain what this error means in plain English
2. Tell me the most likely cause
3. Give me the exact code changes or commands I need to fix it
4. Show me how to prevent this error in the future
Got a different error?
Paste any error into the free Error Decoder and get it explained in plain English, with a fix prompt.
Decode my error