React应用里Invalid hook call错误消息的处理
2020-02-17 05:22
344 查看
今天我做React开发时,遇到如下的错误消息:
Error: 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
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
这个错误输出已经提醒了我,出错误的代码在我的应用程序MyApp.jsx里:
原来是我这段const变量初始化代码写到function外部了:
将其移至内部后错误消失:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- SAP UI5 Web Component React应用如何在Component之间跳转
- SAP UI5 Web Component不同React页面的跳转实现
- SAP UI5 Web Component的React表格控件用法
- SAP UI5 Web Component里最简单的React列表控件的用法
- SAP UI5 Web Component for React的图标和图片处理
- 如何实现SAP UI5 Web Component React控件的加载效果
- 如何使用SAP UI5 web Component的React框架的柱状图和折线图
- 如何使用SAP UI5 Web Component for React的padding功能
- SAP UI5 web Com 4000 ponent的React组件,如何实现事件响应
- 012、Project Reactor
- 使用 React-Sketchapp
- react
- react 入门
- React入门Today.2(JSX、元素渲染)
- React入门Today.3(组件与Props)
- React入门Today.4(State与生命周期)
- React入门Today.5(事件处理与条件渲染)
- react路由时,不能正常渲染,需要刷新,才能渲染
- React脚手架安装及环境变量解析
- 《React设计模式+最佳实践》最新