reactjs - react-bootstrap-table2 和钩子状态奇怪的行为
问题描述
我的问题是,当我尝试删除数据源中的对象时,出现严重错误,删除的项目再次出现......
当我从位置一开始按顺序删除它们时,没有任何问题,但是当我开始删除中间某处的项目时,它会出错。
我用扩展运算符定义了以下状态对象,包括 3 个对象
const [ticketfield, setTicketfield] = useState([
{
id: uuidv4(),
active: "true",
fieldName: "name",
label: "Full Name",
maxChar: "60"
}
,
{
id: uuidv4(),
active: "true",
fieldName: "e-mail",
label: "E-mail address",
maxChar: "60"
}
,
{
id: uuidv4(),
active: "true",
fieldName: "dateOfBirth",
label: "Date of Birth",
maxChar: "10"
}
]
然后我创建了一个删除处理程序
const handleDeleteRow = (row) => {
const ticketfieldNew = [...ticketfield]
setTicketfield(ticketfieldNew.filter(field => field.id !== row.id));
};
在列配置中,我使用格式化程序向上面的处理程序添加了一个带有带有 onclick 引用的按钮的操作列。
// other colums
{
text: "Actions",
formatter: (cell, row, enumObject, rowIndex) => {
return (<Button onClick={() => handleDeleteRow(row)}>Delete</Button >)
},
sort: true,
headerStyle: {
backgroundColor: "#e7e7e7",
},
}
Setup the table in jsx
<ToolkitProvider
keyField="id"
data={ticketfield}
columns={columnsForTicketFields}
cellEdit={cellEditFactory({ mode: "click" })}
>
{(props) => (
<div>
<BootstrapTable
{...props.baseProps}
cellEdit={cellEditFactory({ mode: "dbclick" })}
rowEvents={rowEvents}
pagination={paginationFactory()}
/>
</div>
)}
</ToolkitProvider>
有人知道这里出了什么问题吗?
解决方案
推荐阅读
- javascript - 如何在 HTML 属性中使用条件?
- c# - IndexManyAsync 和 BulkAsync 有什么区别?
- javascript - 如何同时收听单击和双击右键
- c++ - 初始化 Pair 的向量
带有 emplace_back - python - 模拟股市收益的随机数
- ios - iPhone Cordova 应用程序不断闪烁白色
- bookdown - 单个页面上没有引用...?
- reactjs - 加载资源:上传 React/Node/Express 后的 net::ERR_CONNECTION_REFUSED
- python - ValueError:传递值的形状为 (12, 8),索引暗示 (12, 12) 和 .describe()
- python - 使用 python 运行指令时出错