我正在使用react-table,这是我的表格:
<ReactTable
data={this.props.data}
columns={[
{
Header: "id",
accessor: "id",
width: 50
},
{
Header: "Name",
accessor: "name",
width: 200
},
{
Header: "",
id: "id",
Cell: ({ row }) => (
<button onClick={e => this.handleButtonClick(e, row)}>
Click Me
</button>
)
}
]}
defaultPageSize={10}
showPaginationBottom
/>
按钮点击后的操作
handleButtonClick = (e, row) => {
this.setState({ visible: true});
return
<Modal
title="title"
visible={this.state.visible}
>
// show data here
</Modal>
};
所以这就是我现在的工作方式,但模式并没有显示出来。谁能帮我这个?我做错了什么?
答案 0 :(得分:1)
为什么要使用handleButtonClick
函数返回模态而不是将其添加到ReactTable
<ReactTable
data={this.props.data}
columns={[
{
Header: "id",
accessor: "id",
width: 50
},
{
Header: "Name",
accessor: "name",
width: 200
},
{
Header: "",
id: "id",
Cell: ({ row }) => (
<button onClick={e => this.handleButtonClick(e, row)}>
Click Me
</button>
)
}
]}
defaultPageSize={10}
showPaginationBottom
/>
{this.state.visible && <Modal
title="title"
visible={this.state.visible}
>
// show data here
</Modal>}
handleButtonClick = (e, row) => {
this.setState({ visible: true});
};