While attempting to use React Hooks in NextJS I continue to receive the following error:
Hooks can only be called inside the body of a function component.
This issue only occurs on Windows and works fine using Mac.
This is a well documented issue and I have troubleshot many of the proposed solutions, including:
- Multiple versions of React or React DOM
- Modifying webpack settings in
next.config.js - Linking to specific node module pacakges
Here is an example of use:
import React, { useState, useEffect } from 'react'
const Index = () => {
const [ test, setTest ] = useState('Test')
useEffect(() => (
console.log(`Page loaded, variable value: ${test}`)
), [])
return <div>Hello</div>
}
I am using the following versions:
"next": "^9.1.1",
"react": "^16.10.2",
"react-dom": "^16.10.2"