关于react.hook的Invalid hook call Hooks can only be called inside of the body of a function component问题

错误:

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: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the

原因:

   这个也在网上找了许多解释的方法,有以下几点:

  (1)react-redux版本太高,降低版本就可以,但是对我这个好像不奏效

  (2)书写react.hook代码规范有问题,先确保你写的react.hook的代码是没有问题的,可以先阅读一边react.hook规范仔细检查一次,如果没错继续往下看

 (3)react.dom版本太高因为我执行一了遍npm i 把我的react.dom更新到了最新16.13.1,更新完成之后我得项目就直接报错了,起都起不来,网上找了一大堆也不管用,最后想到可能是版本太高的问题就npm install --save react@^16.12.0 react-dom@^16.12.0试了一下降低了react.dom的版本,最后又重新编写了一下就成功运行了

在此纪念下

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。