React项目中Invalid hook call及dispatcher is null错误排查求助
React项目中Invalid hook call及dispatcher is null错误排查求助
最近在做React项目的时候卡壳了,碰到个钩子调用的错误,弹出来的警告提示是:
Warning: 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
除此之外,我还偶尔会碰到dispatcher is null的相关报错,对着官方文档翻了好几遍,也自己试了一些排查方法,比如检查有没有在循环、条件判断里用Hook,有没有在类组件里硬塞Hook,但还是没找到问题根源。
想问问有没有大佬遇到过类似的情况,能不能给我分享下排查的思路或者解决办法呀?比如有没有可能是依赖安装的问题?或者打包配置哪里出了岔子?
备注:内容来源于stack exchange,提问作者Ajay A
相关产品推荐
相关产品推荐

