Next.js: Error: Invalid hook call. Hooks can only be called inside of the body of a function component — Cannot read properties of null (reading 'useContext')
Two copies of React are loaded (or React/ReactDOM versions differ), so hooks can't find the active renderer.
Invalid hook call. Hooks can only be called inside of the body of a function componentTypeError: Cannot read properties of null (reading 'useContext') Next.jsCannot read properties of null (reading 'useState')Warning: Invalid hook callYou might have more than one copy of React in the same app Meaning
Common with linked/monorepo packages, duplicated node_modules, or a library bundling its own React. Run npm ls react react-dom to see duplicates, dedupe (npm dedupe), align versions, and set resolve.alias / transpilePackages for local packages. Ensure the hook is called inside a component or custom hook.
Common causes
- Multiple React copies (npm link, monorepo)
- react and react-dom version mismatch
- Library with React as a dependency instead of peer
- Hook called outside a component
- Different React in
appvs packages
⚡ Quick fix
npm ls react react-domthen dedupe- Make libraries use
peerDependenciesfor React transpilePackages: ["my-ui"]for local packages
Detailed fix by platform
Linux
npm ls react react-dom && npm dedupe
How to diagnose
- Count — One React copy?
- Versions — Match?
- Link — Local package?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- async useEffect Warning: useEffect must not return anything besides a function, which is used for clean-up. It looks like you wrote useEffect(async () => ...)
- Conflicting app and page file was found Next.js: ⨯ Conflicting app and page file was found, please remove the conflicting files to continue: "pages/index.tsx" - "app/page.tsx"
- CORS error calling Next.js API route / route handler Browser: Access to fetch at 'https://api.example.com/api/data' from origin 'https://app.example.com' has been blocked by CORS policy (Next.js route handler)
Most viewed in Next.js
- NEXT_REDIRECT Next.js: Error: NEXT_REDIRECT (redirect() inside try/catch)
- server-only Next.js: You're importing a component that needs "server-only". That only works in a Server Component
- cookies() should be awaited Next.js 15: Route "/x" used `cookies().get('token')`. `cookies()` should be awaited before using its value
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026