关于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的版本,最后又重新编写了一下就成功运行了

在此纪念下

你可能感兴趣的:(关于react.hook的Invalid hook call Hooks can only be called inside of the body of a function component问题)