我正在开发一个react,它运行得很好,直到我安装了react路由器-dom并试图将它导入到我的App.js文件中,我得到了这个错误:
*错误:无效的钩子调用。钩子只能在函数组件的主体内调用。这种情况的发生有以下原因之一:
我尝试了一些这方面的工作,但没有成功,我不会违反规则钩子可以请人帮助我。
https://github.com/facebook/react/issues/15315
我的json包裹如下:
{
"name": "rmdb-react",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"styled-components": "^5.3.0",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": " react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"preinstall": "npx npm-force-resolutions"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"resolutions": {
"react": "^17.0.2"
}
}发布于 2021-08-22 09:23:18
在你的package.json中没有反应路由器.另外,您能否共享抛出错误的代码。
https://stackoverflow.com/questions/68879917
复制相似问题