Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closed #3017
closed #3022
问题:
拖拽后再去编辑,节点又被重置到之前的位置,原因是通过 useTreeAction 生成的 ActionTree 组件中使用的 data 和 Tree 组件中的 data 数据状态不一致。
解决方案:
遇到该场景,可以在 onDragEnd 回调中拿到第三个参数(更新后的 treeData),去更新 data,示例代码如下:
`export const Editable = () => {
const ActionTree = useTreeAction(Tree)
const [data, setData] = React.useState([])
return (
<ActionTree
expandOnSelect
editPlaceholder="请填写菜单"
menuOptions={[]}
data={data}
onDragEnd={(evt, options, treeData) => {
setData(treeData)
}}
/>
)
}`