如何为 react-table 组件添加 ID?

Fer*_*Via 2 javascript reactjs react-table

我正在尝试向我创建的一堆反应表添加一个唯一的 id。我创建了一个使用 react-table 的自定义组件。

我已经尝试将 id 道具添加到标签中,但这不起作用,我猜这是因为库中没有定义 id 道具?

return <ReactTable data={props.data} columns={columns} showPagination={false} minRows={5} style={{height :"400px"}} id='someId'/>;
Run Code Online (Sandbox Code Playgroud)

我期待这将 id 属性添加到 react-table 库创建的 div 中,但这并没有发生

Tri*_*ych 7

看起来 React Table 是通过getPropsReactTable 元素上的属性来处理这个的,它需要一个回调来返回你的自定义属性。在您的render()函数中尝试以下代码段。

const customProps = { id: 'my-table-id' };

return (
  <ReactTable
    data={props.data}
    columns={columns}
    showPagination={false}
    minRows={5}
    style={{height :"400px"}}

    getProps={() => customProps}
  />
);
Run Code Online (Sandbox Code Playgroud)