我正在使用 ionic-react 并且一切都很顺利,但是当我尝试从 react 钩子使用 useState 时,我遇到了这个问题: 我的尝试:
问题仍然存在。
该应用程序在不使用钩子的情况下运行流畅,但非常需要,如果有替代方案,我也可以使用。
注意: 我没有在这个问题中明确创建反应库 here 我使用 npm 安装了所有依赖项
这是我的包 json 文件:
{
"name": "frontend-client-cpp",
"version": "0.0.1",
"private": true,
"dependencies": {
"@ionic/react": "^5.6.5",
"@ionic/react-router": "^5.6.5",
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.6.3",
"@types/jest": "^26.0.20",
"@types/node": "^12.19.15",
"@types/react": "^16.14.3",
"@types/react-dom": "^16.9.10",
"@types/react-router": "^5.1.11",
"@types/react-router-dom": "^5.1.7",
"ionicons": "^5.4.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.2",
"typescript": "^4.1.3",
"web-vitals": "^0.2.4",
"workbox-background-sync": "^5.1.4",
"workbox-broadcast-update": "^5.1.4",
"workbox-cacheable-response": "^5.1.4",
"workbox-core": "^5.1.4",
"workbox-expiration": "^5.1.4",
"workbox-google-analytics": "^5.1.4",
"workbox-navigation-preload": "^5.1.4",
"workbox-precaching": "^5.1.4",
"workbox-range-requests": "^5.1.4",
"workbox-routing": "^5.1.4",
"workbox-strategies": "^5.1.4",
"workbox-streams": "^5.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"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"
]
},
"description": "An Ionic project"
}
答案 0 :(得分:0)
在您的 package.json
中,缺少依赖项 "@ionic/react-hooks"
,因此请安装它:
$ npm install @ionic/react-hooks