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' state: 'new'
} }
setRows((prev) => [...prev, newRow])
// Start editing the material name cell // 在 setRows 回调中计算索引并设置编辑状态
const newIndex = rows.length setRows((prev) => {
const newIndex = prev.length
setTimeout(() => { setTimeout(() => {
setEditingCell({ rowIndex: newIndex, field: 'materialName' }) setEditingCell({ rowIndex: newIndex, field: 'materialName' })
setEditValue('') setEditValue('')
}, 0) }, 0)
return [...prev, newRow]
})
} }
// Delete row // Delete row