fix(component): fix race condition in MaterialTypeManagementDialog row addition

Use functional setState to correctly calculate new row index based on
latest state, preventing stale closure issues.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
test
2026-03-07 15:50:47 +08:00
parent 73b8f2409a
commit 2d6838c0e7

View File

@@ -147,13 +147,16 @@ export const MaterialTypeManagementDialog: React.FC<MaterialTypeManagementDialog
},
state: 'new'
}
setRows((prev) => [...prev, newRow])
// Start editing the material name cell
const newIndex = rows.length
// 在 setRows 回调中计算索引并设置编辑状态
setRows((prev) => {
const newIndex = prev.length
setTimeout(() => {
setEditingCell({ rowIndex: newIndex, field: 'materialName' })
setEditValue('')
}, 0)
return [...prev, newRow]
})
}
// Delete row