离子反应中的反应钩子使用状态错误

问题描述

我正在使用 ionic-react 并且一切都很顺利,但是当我尝试从 react 钩子使用 useState 时,我遇到了这个问题:

useState error

我的尝试

  1. 使用“npm update”将所有包更新到项目文件夹中的最新版本
  2. linking with react and react dom(第一个答案)
  3. 正在更改我的 package.json 文件

问题仍然存在。

该应用程序在不使用钩子的情况下运行流畅,但非常需要,如果有替代方案,我也可以使用。

注意: 我没有在这个问题中明确创建反应库 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"
}

解决方法

在您的 package.json 中,缺少依赖项 "@ionic/react-hooks",因此请安装它: $ npm install @ionic/react-hooks

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...