oppddd
V2EX  ›  React

使用 antd/procomponents/pro-table 中的困惑

  •  1
     
  •   oppddd · Mar 2, 2023 · 2337 views
    This topic created in 1191 days ago, the information mentioned may be changed or developed.
    4 replies    2023-03-09 09:44:52 +08:00
    oppddd
        1
    oppddd  
    OP
       Mar 2, 2023
    react-query 的请求方式

    ```tsx
    const { data, isLoading, refetch } = useQuery(['org-user-table', orgId, query], {
    queryFn: () => {
    return queryUserListUsingPOST({
    size: query.pageSize || 20,
    current: query.current || 1,
    byCondition: {
    name: query.name,
    orgId: Number(orgId) || 0,
    state: query.state || '',
    },
    })
    },
    })
    ```

    ```tsx
    <ProTable
    // 请注意修改主键 id
    rowKey={'roleId'}
    columns={columns}
    pagination={{ pageSize: 10, showQuickJumper: true }}
    request={
    // 这里发起请求
    () => {
    return Promise()
    }
    }>
    </ProTable>
    ```

    这两个怎么配合啊,因为 ant 官方推荐使用 request 请求(会自己管理请求参数,分页等);
    Sendya
        2
    Sendya  
       Mar 2, 2023
    类似这样


    ```tsx
    <ProTable
    rowKey={'roleId'}
    columns={columns}
    request={async (params, sorter) => {
    const { data, total = 0 } = await queryUserListUsingPOST(params);
    return {
    data,
    totla,
    success: true,
    }
    }}
    />

    ```
    oppddd
        3
    oppddd  
    OP
       Mar 3, 2023
    嗯,我其实想让 table 变成木偶组件;这样我就可以使用 react-query 了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1042 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 23:08 · PVG 07:08 · LAX 16:08 · JFK 19:08
    ♥ Do have faith in what you're doing.