調用hook組件時報錯Hooks can only be called inside of the body of a function component


在調用其他項目中的hook組件時,報錯信息:無效的鈎子調用。鈎子只能在函數組件的主體內部調用。這可能是由於以下原因之一:

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 Rules of Hooks
3. 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.

A庫調用B,B使用的是npm link調試,會導致react的依賴出現兩次,所以需要在B中link到A下面的react,重啟項目

npm link G:\git\phoenix\node_modules\react
npm link G:\git\phoenix\node_modules\react-dom

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM