gpt4 book ai didi

reactjs - Material UI React 表卡在切换选项卡上

转载 作者:行者123 更新时间:2023-12-03 19:06:09 28 4
gpt4 key购买 nike

我使用对这些组件使用react来创建 SPA:BrowserRouter、Route、Link、AppBar、Toolbar、Tabs、Tab、MaterialTable。
一切正常,除了当我在选项卡之间快速切换(单击 PAGE1、PAGE2 链接)时,浏览器会挂起。这发生在 Chrome 和 Firefox 中。我没有使用任何状态或钩子(Hook)。
密码箱链接:https://codesandbox.io/s/winter-pond-1zsn3?file=/public/index.html
应用程序.js:

import React from "react";
import "./styles.css";
import { BrowserRouter, Route, Switch } from "react-router-dom";
import Page1 from "./Page1";
import Page2 from "./Page2";
import Header from "./Header";

export default function App() {
return (
<BrowserRouter>
<Header />
<Switch>
<Route exact path="/Page1" component={Page1}></Route>
<Route exact path="/Page2" component={Page2}></Route>
</Switch>
</BrowserRouter>
);
}
页眉.jsx
import React from "react";
import { Link } from "react-router-dom";
import { AppBar, Toolbar, Tabs, Tab } from "@material-ui/core";

const Header = () => {
return (
<AppBar position="static">
<Toolbar>
<Tabs>
<Tab label="Page1" to="/Page1" component={Link} />
<Tab label="Page2" to="/Page2" component={Link} />
</Tabs>
</Toolbar>
</AppBar>
);
};

export default Header;
Page1.jsx
import React from "react";

const Page1 = () => {
return <div>Page1</div>;
};

export default Page1;
Page2.jsx
import React from "react";
import MaterialTable from "material-table";

const taskColumns = [
{ title: "Task Name", field: "TaskName" },
{ title: "Task Description", field: "TaskDesc" }
];
const Page2 = () => {
return <MaterialTable title="Task List" columns={taskColumns} data={[]} />;
};

export default Page2;

最佳答案

如本文所述 github issue thread ,降级到版本。 1.68.0 将解决这个问题。

yarn add material-table@1.68.0


或者

npm install material-table@1.68.0

关于reactjs - Material UI React 表卡在切换选项卡上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63602354/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com