# 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')

**Code:** `Invalid hook call (duplicate React in Next.js)` · **Category:** Next.js · **Seen on:** Next.js, React

Two copies of React are loaded (or React/ReactDOM versions differ), so hooks can't find the active renderer.

## 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 `app` vs packages

## Quick fix

1. `npm ls react react-dom` then dedupe
2. Make libraries use `peerDependencies` for React
3. `transpilePackages: ["my-ui"]` for local packages

## Detailed fix by platform

### Linux

1. `npm ls react react-dom && npm dedupe`

## How to diagnose

1. **Count** — One React copy?
2. **Versions** — Match?
3. **Link** — Local package?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nextjs/invalid-hook-call-duplicate-react-next)
