I am getting this error when using the useState
hook. I have this in it's basic form, looking at the react docs for a reference, but am still getting this error. I'm ready for the face palm moment…
export function Header() {
const [count, setCount] = useState(0)
return <span>header</span>
}
Best Answer
Updated: 2018-Dec
New version of
react-hot-loader
is out now, link. Hooks is now working out of the box. Thank to the author, theKashey.Check out this boilerplate https://github.com/ReeganExE/react-hooks-boilerplate
Previous Answer:
First, make sure you installed
react@next
andreact-dom@next
.Then check for you are using
react-hot-loader
or not.In my case, disable hot loader & HMR could get it work.
See https://github.com/gaearon/react-hot-loader/issues/1088.
Quoted:
There is a more proper fix, which would work - cold API
You may disable RHL for any custom type.
Search for
"useState/useEffect"
inside component source code, and "cold" it.Updated:
As per updated from react-hot-loader maintainer, you could try
react-hot-loader@next
and set the config as bellow:Thank to @loganfromlogan for the update.