[SOLVED] Cannot read properties of null (reading 'useContext')

Hello, I’m getting this error Cannot read properties of null (reading ‘useContext’)

while using

import { useChain, useMoralis } from "react-moralis";
const { isAuthenticated } = useMoralis();

despite i’ve set the context in my app.js

import { MoralisProvider } from "react-moralis";

 return (
    <MoralisProvider initializeOnMount={false}>
      <Component {...pageProps} />
    </MoralisProvider >
  )

what line gives that error?

that error means that a variable was null, a variable that was used before useContext, like variable.useContext

This line is giving me error

Where exactly are you using this line? Make sure this hook is being used inside a function component.

I’m using it in a function component header.jsx

import { useChain, useMoralis } from "react-moralis";
const { isAuthenticated } = useMoralis();

followed with my component


export default function Home() {
  return (
<div>blah blah</div>
)}

thanks got it resolved. i had to use the useMoralis inside the function.

1 Like