Cannot read properties of null (reading 'useContext')
Unanswered
ABUL KALAM posted this in #help-forum
react-dom.development.js:17378 Uncaught Error: Cannot read properties of null (reading 'useContext')This error randomly pops up during development in my Next.js app.
Sometimes, a similar error pops up for
useState()I have imported
useContext() in only 3 files, and I have used it directly inside the component/hook body.AlertContainer component which is used in layout.js under AlertProvider.Alert being imported and used in AlertContainer.useShowAlert hook, (the issue was there even before using this custom hook).VS Code console
Warning: 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 the renderer (such as 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
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
⨯ TypeError: Cannot read properties of null (reading 'useContext')
at useShowAlert (./src/hooks/useShowAlert.js:11:76)
at ReadyProjectClientPage (./src/components/admin-side/ready-project/ReadyProjectClientPage.js:32:88)