【发布时间】:2022-09-30 20:07:08
【问题描述】:
我有使用状态:
const [localImportedCustomers, setLocalImportedCustomers] = useState([]);
和模板,以显示数据:
<tbody>
{
localImportedCustomers.map((value, index) => {
return (
<tr key={index}>
<td>{index+1}</td>
{
value.map((value1, index1) => {
return (
<td key={index1}>{value1}</td>
)
})
}
<td>
<button
className=\"c-btn c-btn-danger\"
onClick={ (e) => { deleteRow(e, index) } }
>
<FaTrash />
</button>
</td>
</tr>
)
})
}
</tbody>
尝试通过以下功能删除特定行:
const deleteRow = (e, index) => {
e.preventDefault();
let tmpArray = localImportedCustomers;
tmpArray.splice(index, 1);
setLocalImportedCustomers(tmpArray);
}
但是模板没有更新,应该有人有这样的问题吗?感谢您在时间之前的回答!
标签: reactjs react-hooks updating