getting error "TypeError: Cannot read properties of null (reading 'useState')" on useState usage react
Full error message
So I'm trying to use useState in my nextjs app, but as soon as I add in the line of code to initialize useState it throws a popup error with the error message: TypeError: Cannot read properties of null (reading 'useState')
Here is a simplified version of my code:
import { useState } from 'react'
export default function Home() {
return (
<div>
<Transactions />
</div>
)
}
const Transactions = () => {
const [state, setState] = useState('test')
...
}
React/Next versions I'm running:
"next": "12.1.5",
"react": "18.0.0",
"react-dom": "18.0.0"
Screenshot of error from chrome dev tools:
Any thoughts on what's causing this? Thanks
EDIT
Very dumb bug on my end, issue was resolved by importing react...Solutionsource: stackoverflow \u2197
If you are using Next 13 App router this could be happening if you are using an async function Wrong: "use client" export default async function Page() { const [variable, setVariable] = useState(); } Right: "use client" export default function Page() { //Remove Async Keyword const [variable, setVariable] = useState(); }
API access
Get this solution programmatically \u2014 free, no authentication.
curl https://depscope.dev/api/error/29991aec8fe0c7bb311e65aa42121d102fc0a2d5aeca27a7d9eb1b3d8be921dahash \u00b7 29991aec8fe0c7bb311e65aa42121d102fc0a2d5aeca27a7d9eb1b3d8be921da