React应用里Invalid hook call错误消息的处理
生活随笔
收集整理的這篇文章主要介紹了
React应用里Invalid hook call错误消息的处理
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
今天我做React開發(fā)時,遇到如下的錯誤消息:
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:
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
這個錯誤輸出已經(jīng)提醒了我,出錯誤的代碼在我的應(yīng)用程序MyApp.jsx里:
原來是我這段const變量初始化代碼寫到function外部了:
將其移至內(nèi)部后錯誤消失:
要獲取更多Jerry的原創(chuàng)文章,請關(guān)注公眾號"汪子熙":
總結(jié)
以上是生活随笔為你收集整理的React应用里Invalid hook call错误消息的处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为宣布开放5G网络能力 自家5.5G比
- 下一篇: SAP UI5 Web Componen