小编JS3*_*JS3的帖子

如何在 React Router v6 中使用 withRouter 来传递 props?

以前,你需要包装这样的东西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以前一样做到这一点?

javascript reactjs react-router-dom

11
推荐指数
1
解决办法
3万
查看次数

如何将 firestore 中的动态数据放入函数 where() 中,并使用 snap.size 来计算要在图表中传递的总查询数?

我有来自 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)

javascript firebase reactjs google-cloud-firestore

7
推荐指数
1
解决办法
499
查看次数

处理登录错误消息时出错:http://localhost:3000/auth/login net::ERR_ABORTED 405(方法不允许&gt;)

我有这个/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)

javascript typescript reactjs next.js supabase

5
推荐指数
1
解决办法
395
查看次数

当单击来自 custombodyrender 的操作按钮时,如何阻止 onRowClick?

我正在使用 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)

reactjs material-ui mui-datatable

4
推荐指数
1
解决办法
3411
查看次数

Material-UI DataGrid,显示列的总和并根据过滤器更新总和

我有这个 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)

javascript datagrid reactjs material-ui

3
推荐指数
1
解决办法
7814
查看次数

如何使可滚动选项卡居中?

有 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)

reactjs material-ui

2
推荐指数
1
解决办法
3727
查看次数

错误:类型“FormDataEntryValue”无法分配给类型“string”。类型“文件”不可分配给类型“字符串”

我有从 获得的数据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)

InvoiceEmailDatafor firstNamelastName和上发生错误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)

javascript typescript reactjs next.js

1
推荐指数
1
解决办法
917
查看次数

React-chart.js 2 模块出错,但已安装在 package.json 文件中

我已经安装了 React Chart JS 2 但仍然有这种错误

./node_modules/react-chartjs-2/dist/index.modern.js 找不到模块:无法解析“chart.js”

这是我的 package.json 文件 在此输入图像描述

条形图.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)

javascript reactjs react-chartjs-2

0
推荐指数
1
解决办法
9257
查看次数