【问题标题】:React Hooks(use State) Error in Ionic react离子反应中的反应挂钩(使用状态)错误
【发布时间】:2021-07-19 06:50:03
【问题描述】:

我正在使用 ionic-react,一切都很顺利,但是当我尝试使用 react hooks 中的 useState 时,我遇到了这个问题: 我尝试过的

  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"
}

【问题讨论】:

  • 试试const Home = () => {...,不要输入React.FC。我认为这是多余的
  • 我试过了,还是一样的错误。我什至尝试了js的原始函数语法:export default function Home()
  • 尝试将 React 降级为 >=16.8.6?

标签: reactjs react-hooks ionic-react


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-03-22
    • 2022-11-01
    • 2021-10-12
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-30
    相关资源
    最近更新 更多