这是我第一次在示例项目中使用Stackblitz,我一直遇到以下错误:
Error in /turbo_modules/react@16.10.2/cjs/react.development.js (1607:26)
Invalid hook call.该项目在本地运行良好,能够在Stackblitz上进行编译,但当我单击一个按钮时,就会发生错误。
https://stackblitz.com/edit/react-ef9gan
在从'import react from 'react'到import React, { Component } from 'react'组件中的导入语句中
我还从stackblitz中删除了react-router-dom依赖项,因为这个项目不需要它。
根据这些文件,出现这种情况的原因有三个:
There are three common reasons you might be seeing it:
1. You might have mismatching versions of React and 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.在这两种情况下,我的本地项目和示例都在运行16.9.0。locally.
我看了一下这个问题,why material-UI textField returns 'Invalid hook call' error有一个解决方案,但是它是更新React的版本,所以我不知道从哪里开始让它正确编译。
发布于 2019-10-20 09:16:53
升级您的反应性依赖修复它。
https://stackblitz.com/edit/react-wk49k9?file=index.js
如果第三方程序包作者没有将react指定为对等依赖项,则这些问题更多地发生在较新版本的react上。这通常会导致安装多个版本的react - node_modules中的packages文件夹--触发此错误。
https://stackoverflow.com/questions/58471208
复制相似问题