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:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user