无法在项目中使用react hooks
Closed this issue · 11 comments
Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- You might have more than one copy of React in the same app
egg See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
已经检测过react和react-dom版本,是一致的。
npm ls react-dom
xx@2.3.3 /Users/xx/cj/xx
├── react-dom@16.13.1 -> /Users/xx/xx/xx/node_modules/_react-dom@16.13.1@react-dom
├─┬ yk-cli@3.1.4 -> /Users/xx/xx/xx/node_modules/_yk-cli@3.1.4@yk-cli
│ └── react-dom@16.13.1 -> /Users/xx/xx/xx/node_modules/_react-dom@16.13.1@react-dom
└─┬ ykfe-utils@3.6.12 -> /Users/xx/xx/xx/node_modules/_ykfe-utils@3.6.12@ykfe-utils
└── react-dom@16.13.1 -> /Users/xx/xx/xx/node_modules/_react-dom@16.13.1@react-dom
参考:npm包react-server-render不支持react-hooks的原因和解决方法 。https://zhuanlan.zhihu.com/p/57651697
并不会使用不了react-hooks请提供复现仓库。这个错很早就专门修复过了。
并且await后,react中的componentDidMount事件在移动端没有进行执行
没用过国际化理论上来说应该不会导致。。就是你的写法看起来很迷。。为什么会return一个await表达式。
去layout组件或者具体的业务组件做吧
在layout组件里面就没法使用import国际化文件,只能使用script标签引入国际化脚本
不要在组件顶层直接import这块代码会在服务端客户端都执行。去看文档faq __isBrowser__相关部分。或者直接用script标签
有存放静态资源的目录吗
有,先看完官方文档和egg文档再提问