以前,你需要包装这样的东西export default withRouter(name of component)
,现在在react-router v6中有所不同。
我有这个按钮,一旦您单击此按钮,它将带您进入另一个页面,其中包括 my tableMeta.rowData[0]
. 我尝试使用navigate = useNavigate()
,但我不知道如何传递 的值tableMeta.rowData[0]
{
name: "Edit",
options: {
customBodyRender: (value, tableMeta, updateValue) => {
return (
<Button
color="success"
onClick={
() => navigate("/edit-products")
// console.log(tableMeta.rowData[0])
}
>
Edit
</Button>
);
},
},
},
Run Code Online (Sandbox Code Playgroud)
在 React-router v6 中,我怎样才能像withRouter
以前一样做到这一点?
我有来自 firestore 的数据,我想使用 a 动态检索它,where()
但这是我收到的错误:
类型错误:疫苗不是函数
用户集合:
[![在此处输入图像描述][1]][1]
下面是代码:
const Vaccine = () => {
const [vaccines, setVaccines] = useState([]);
useEffect(() => {
const unsubscribe = firestore
.collection("vaccines")
.onSnapshot((snapshot) => {
const arr = [];
snapshot.forEach((doc) =>
arr.push({
...doc.data(),
id: doc.id,
})
);
setVaccines(arr);
});
return () => {
unsubscribe();
};
}, []);
Run Code Online (Sandbox Code Playgroud) 我有这个/app/auth/login/route.ts
import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers'
import { NextResponse } from 'next/server'
export async function POST(request: Request) {
const requestUrl = new URL(request.url)
const formData = await request.formData()
const email = String(formData.get('email'))
const password = String(formData.get('password'))
const cookieStore = cookies()
const supabase = createRouteHandlerClient({ cookies: () => cookieStore })
await supabase.auth.signInWithPassword({
email,
password,
})
return NextResponse.redirect(requestUrl.origin, {
status: 301,
})
}
Run Code Online (Sandbox Code Playgroud)
以及/app/login/page.tsx上的页面
import Link from "next/link";
export default function LoginPage() { …
Run Code Online (Sandbox Code Playgroud) 我正在使用 mui-datatable,其中 onRowClick 将引导用户到另一个页面。我还在每一行都有自定义操作按钮。但是,如果我单击自定义操作按钮,它还会触发 onRowClick,从而将用户引导到另一个页面。单击自定义操作按钮时如何防止 onRowClick?
class orders extends Component {
constructor() {
super();
this.state = { orders: [] };
}
handleRowClick = (rowData, rowMeta) => {
this.props.history.push("/details", `${rowData[0]}`);
};
columns = [
"Order ID",
"Items",
"Address",
"Total Amount",
{
name: "Action Button",
options: {
filter: true,
sort: false,
empty: true,
customBodyRender: (value, tableMeta) => {
return (
<FormControlLabel
value={value}
control={
<Button
value={value} >
Action Button
</Button>
}
onClick={(e) => {
//firestore codes
}}
/>
);
},
},
},
]; …
Run Code Online (Sandbox Code Playgroud) 我有这个 Material-UI DataGrid,如何对“总金额”列的所有值求和,一旦触发过滤器,该列的值也会更新?
我真的不确定如何对整个列的总金额进行求和。任何帮助,将不胜感激。谢谢
代码:
const [filterModel, setFilterModel] = React.useState({
items: [
{
columnField: "totalAmount",
operatorValue: ">",
value: "200"
}
]
});
return (
<div style={{ height: 400, width: "100%" }}>
<DataGrid
// rows={rows}
columns={columns}
rows={data}
components={{
Toolbar: GridToolbar
}}
filterModel={filterModel}
onFilterModelChange={(newFilterModel) => setFilterModel(newFilterModel)}
/>
</div>
);
}
Run Code Online (Sandbox Code Playgroud) 有 3 个选项卡,我无法将它们放在屏幕中央。如何使可滚动选项卡居中?截至目前,它只会出现在屏幕的左侧
codesandbox:https://codesandbox.io/s/material-demo-forked-dbcxl?file =/demo.js
下面是代码:
import * as React from "react";
import Tabs from "@mui/material/Tabs";
import Tab from "@mui/material/Tab";
import Box from "@mui/material/Box";
export default function ScrollableTabsButtonAuto() {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Tabs
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons="auto"
aria-label="scrollable auto tabs example"
centered
>
<Tab label="Item One" />
<Tab label="Item Two" />
<Tab label="Item Three" />
</Tabs>
);
}
Run Code Online (Sandbox Code Playgroud) 我有从 获得的数据formData
,我希望将其传递给发送电子邮件的功能。
错误:
Type 'FormDataEntryValue' is not assignable to type 'string | null'.ts(2322)
definitions.ts(119, 3): The expected type comes from property 'lastName' which is declared here on type 'InvoiceEmailData'
(property) lastName: string | null
No quick fixes available
Run Code Online (Sandbox Code Playgroud)
InvoiceEmailData
for firstName
、lastName
和上发生错误remarks
。
'use server'
export default async function addCustomerOrder(cart: any, total: number, formData: FormData): Promise<{ message: string }> {
const cookieStore = cookies()
const supabase = createServerActionClient({ cookies: () => cookieStore })
let order_id; …
Run Code Online (Sandbox Code Playgroud) 我已经安装了 React Chart JS 2 但仍然有这种错误
./node_modules/react-chartjs-2/dist/index.modern.js 找不到模块:无法解析“chart.js”
条形图.js
import React from "react";
import { Bar } from "react-chartjs-2";
const state = {
labels: ["Nausea", "Fever", "Muscle Pain"],
datasets: [
{
label: "1st Dose",
backgroundColor: "rgba(75,192,192,1)",
borderColor: "rgba(0,0,0,1)",
borderWidth: 2,
data: [65, 59, 80],
},
{
label: "2st Dose",
backgroundColor: "red",
borderColor: "rgba(0,0,0,1)",
borderWidth: 2,
data: [30, 20, 10],
},
],
};
export default class Barchart extends React.Component {
render() {
return (
<div>
<Bar
data={state}
options={{ …
Run Code Online (Sandbox Code Playgroud) reactjs ×8
javascript ×6
material-ui ×3
next.js ×2
typescript ×2
datagrid ×1
firebase ×1
supabase ×1