[英]react + mobx: "Invalid hook call" in 1 of my 2 machines
I've been following this Mobx tutorial:我一直在关注这个 Mobx 教程:
The code works fine on 1 of my 2 machines.该代码在我的 2 台机器中的 1 台上运行良好。 On the other machine, I get an error message when I run "npm start":
在另一台机器上,当我运行“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
.只要我不使用
observer
包装函数,错误就会消失。
Somehow things work fine after uninstalling and reinstalling mobx卸载并重新安装 mobx 后不知何故一切正常
npm uninstall mobx-react
npm install mobx-react --save
npm audit fix
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.