reactjs 我如何将我的ID值传递给下一个组件?

vmjh9lq9  于 2022-12-29  发布在  React
关注(0)|答案(1)|浏览(140)

我是新的React,有人能告诉我如何才能访问我的ID框中的编辑按钮组件,以便我可以填充我的字段编辑组件从数据库?

const columns = [
  {
    title: "ID", //this is the ID
    dataIndex: "boxId",
    key: "boxId",
  },
  {
    title: "Product Name",
    dataIndex: "name",
    key: "productName",
  },
  {
    title: "Avatar",
    dataIndex: "photoPath",
    key: "avatar",
    render: (src) => <img src={src} alt="" width="80px" height="60px" />,
  },
  {
    title: "Box Sets",
    dataIndex: "numberOfBox",
    key: "boxSets",
  },
  {
    title: "Box Type",
    dataIndex: "boxType",
    key: "boxType",
    render: () => (
      <div>
        <br />
        <Button type="dashed">Reward</Button>
      </div>
    ),
  },
  {
    title: "Sort Value",
    dataIndex: "status",
    key: "sortValue",
  },
  {
    title: "State",
    dataIndex: "status",
    key: "state",
    render: (value) => <Tag color="blue">{value}</Tag>,
  },
  {
    title: "Time",
    dataIndex: "updatedTime",
    key: "time",
  },

  {
    title: "Operations",
    key: "operations",
    render: () => (
      <Row gutter={10}>
        <Col>
          <Link to="/gift-management/edit-box/:boxId"> //This what i am trying to pass to next component
            <Button type="primary" icon={<EditOutlined />}>
              Edit
            </Button>
          </Link>
        </Col>
        <Col>
          <ChangeState />
        </Col>
        <Col>
          <Link to="/gift-management/box-items">
            <Button icon={<ContainerOutlined />}>Box Items</Button>
          </Link>
        </Col>
        <Col>
          <DeleteBox />
        </Col>
      </Row>
    ),
  },
];

我正在尝试访问我的编辑框组件中的boxID,以便我可以从我的数据库中获取数据,并重新填充编辑选项的字段。在其他窗体上,我正在使用formik,并试图从数据库填充其字段。

g6ll5ycj

g6ll5ycj1#

在render方法中使用param

render: (param) => (
      <Row gutter={10}>
        <Col>           
          <Link to={`/gift-management/edit-box/${param.data.boxId}`}>

Demo

相关问题