Reactjs 对历史作出反应。未捕获错误:钩子调用无效

Reactjs 对历史作出反应。未捕获错误:钩子调用无效,reactjs,react-router,react-hooks,Reactjs,React Router,React Hooks,我只有一份React,用npm ls React检查过,React和React dom是同一个版本,我没有违反任何钩子规则,对吗?我不知道该怎么办了 ERROR: Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might

我只有一份React,用npm ls React检查过,React和React dom是同一个版本,我没有违反任何钩子规则,对吗?我不知道该怎么办了

ERROR: Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
我的组成部分:

import React from "react";
import { useHistory } from "react-router-dom";

export default function HomeButton() {
    let history = useHistory();

    function handleClick() {
     history.push("/home");
    }

    return (
    <button type="button" onClick={handleClick}>
      Go home
    </button>
    );
}
解决了,, 在webpack.config.js中添加了以下内容:

 alias: {
        react: path.resolve("./node_modules/react"),
        }

我使用CreateReact应用程序,所以我必须运行npm RunEject,这是不推荐的。有人为未来获得了更好的id吗?

你如何在App.js中呈现
HomeButton
。我运行了npm ls react agian,并注意到我得到了以下结果└── react@16.12.0. 所以我猜是两个版本,有解决方案吗?现在我从react文档中运行了这个,并收到了true,这意味着react://在node_modules/react dom/index.js window.React1=require('react');//中没有两个版本的Add this将其添加到组件文件require('react-dom');window.React2=需要('react');console.log(window.React1==window.React2);你确定这是应用程序中唯一使用react钩子的地方吗?我也在使用CreateReact应用程序。我尝试了你的解决方案,但没有成功。
 alias: {
        react: path.resolve("./node_modules/react"),
        }