I've been following this Mobx tutorial:
The code works fine on 1 of my 2 machines. On the other machine, I get an error message when I run "npm start":
Warning: Invalid hook call. Hooks can only be called inside of the body of a function component.
Uncaught TypeError: Cannot read properties of null (reading 'useState')
at Object.useState (react.development.js:1622:1)
at useObserver (useObserver.ts:29:1)
at observerComponent (observer.ts:104:1)
at renderWithHooks (react-dom.development.js:16305:1)
at updateFunctionComponent (react-dom.development.js:19588:1)
at updateSimpleMemoComponent (react-dom.development.js:19425:1)
at updateMemoComponent (react-dom.development.js:19284:1)
at beginWork (react-dom.development.js:21673:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
Any idea why this is happening? The machines have almost identical setups...
Both machines have the same version for the following:
The error goes away as long as I don't wrap the functions using observer
.
Somehow things work fine after uninstalling and reinstalling mobx
npm uninstall mobx-react
npm install mobx-react --save
npm audit fix