简体   繁体   English

React - 错误,Hookrouter 无效挂钩调用

[英]React - Error, Hookrouter invalid hook call

can't handle this error any suggestions?无法处理此错误有任何建议吗?

 import "./App.css"; import { navigate, useRoutes } from "hookrouter"; const routes = { "/": () => <h1>home</h1>, "/news": () => <h1>news</h1>, }; function App() { const page = useRoutes(routes); return <div>{page || alert("not found")}</div>; } export default App;

this is app.js only this component exists nothing more then this also package.json and i think everything is okay but anyway returning invalid hook call but have no idea why这是 app.js 只有这个组件仅存在然后这也是 package.json 我认为一切都很好但是无论如何返回无效的钩子调用但不知道为什么

{
  "name": "weather",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "@types/hookrouter": "^2.2.5",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.1.2"
  },
  "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"
    ]
  }
}

Have you tried to install the package before using it! package在使用前试过安装吗!

use this command to install the package使用此命令安装 package

npm i hookrouter

//or if you're using yarn try this:

yarn add hookrouter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM