Invalid Hook Call Error in React
“Hooks can only be called inside of the body of a function component.”
React 19 • Next.js 15 • TypeScript • Vite • React Router • Redux Toolkit
🔍 What Is the “Invalid Hook Call” Error?
The “Invalid hook call” error is one of the most common React runtime errors.
It appears when you try to use a Hook — like useState, useEffect,
useContext, or any custom Hook — outside of a React function component or
custom Hook.
The full error message reads:
Invalid hook call. Hooks can only be called inside of the body of a function component.
This could happen for one of the following reasons:
1. You might have mismatching versions of React and React DOM.
2. You might be breaking the Rules of Hooks.
3. You might have more than one copy of React in the same app.
In this guide, we break down every possible cause and give you step-by-step fixes tailored for React 19, Next.js 15, TypeScript, Vite, React Router, and Redux Toolkit. No more trial-and-error.
🎯 Top Causes & Quick Solutions
Hooks don't work in class components. Convert to function component.
Hooks must be called from components or custom Hooks (use prefix).
Call Hooks at the top level — not inside loops or conditions.
Multiple React versions installed. Deduplicate with npm dedupe.
Ensure react and react-dom share the same major version.
Don't call Hooks directly inside onClick or other events.
🧩 Q&A — Every “Invalid Hook Call” Scenario Solved
Below are the most common causes of the invalid hook call error, with detailed explanations and code examples. Each card is built from structured JSON data for clean DOM management.
🛡️ Prevention — Avoid Hook Errors Altogether
Add
eslint-plugin-react-hooks to your project. It automatically catches
violations like conditional Hook calls and missing dependencies.
In monorepos or linked packages, configure your package manager to hoist React to the root
node_modules. Use npm dedupe or yarn dedupe
to remove duplicates.
Always install matching versions:
npm install react@19 react-dom@19.
Use npm outdated to check for updates.
All custom Hooks must start with
use (e.g., useFetch).
This helps React and ESLint enforce the rules.
TypeScript can catch some hook-related issues at compile time, especially when using
useState and useReducer with strict types.
use client directive
at the top of client components to avoid confusion between server and client hooks.
❓ Frequently Asked Questions
This usually happens due to:
- Duplicate React instances — check
npm ls react. - Calling a Hook inside a nested function within your component.
- Conditional Hook calls — Hooks must be called unconditionally at the top level.
- Missing React import — ensure
import React from 'react'is present (or use the new JSX transform).
Solution: systematically check each of these causes.
Yes, indirectly. You can't call Hooks directly in a class component. However, you can create a function component wrapper that uses Hooks and passes data to the class component via props.
// ✅ Wrapper pattern
function Wrapper() {
const [data, setData] = useState(null);
return <ClassComponent data={data} />;
}
This is a common migration strategy when moving from class to function components.
If you've cleared node_modules, restarted, and the error persists:
- Check for duplicate React with
npm ls react. - Look for linked packages that might be using their own React.
- Ensure all third-party libraries are compatible with your React version.
- In a monorepo, verify your hoisting configuration.
- Use React DevTools to inspect which component is causing the error.
No. The Rules of Hooks remain exactly the same in React 19 as
in React 18 and 17. React 19 introduces new Hooks like use
(for promises and contexts) and useOptimistic, but the core rules
— top-level calls only, function components only — still apply.
In production, the error is minified (e.g., Minified React error #185).
- Use the React Error Decoder to get the full message.
- Enable source maps in your production build to trace back to original code.
- Use error tracking services like Sentry, LogRocket, or Datadog.
- Reproduce the error in development — minified errors always have a development equivalent.

0 Comments
thanks for your comments!