I have to do drag and drop tree view using react-sortable-tree. And also I need crud operations in my tree view. I have done to add, edit and delete into my parent node on tree view. Unexpectedly, I have some issues whenever I drag my node that time my first-child will edit and after that updated properly, but could not work delete functions, and also nth-child will not work properly to add, edit and delete node.
Asked
Active
Viewed 1,216 times
1 Answers
1
The problem is you are updating the state using old setState syntax. Like this,
setState({ stateKey: stateValue });
But new useState hook doesn't need the stateKey. You can update the state by just calling the setState(stateValue)
.
So, instead of writing this,
settreeData({
treeData: removeNodeAtPath({
treeData: treeData,
path: path,
getNodeKey: ({ treeIndex: number, node: TreeNode }) => {
return number;
},
ignoreCollapsed: false
})
});
You should write this,
settreeData(
removeNodeAtPath({
treeData: treeData,
path: path,
getNodeKey: ({ treeIndex: number, node: TreeNode }) => {
return number;
},
ignoreCollapsed: false
})
);
Here is the working code link.

Md Sabbir Alam
- 4,937
- 3
- 15
- 30
-
Thank you, it's working well to remove all parent and child nodes... And also need to update data when I clicked to edit data that data need to update that edited node... But, currently, I got an error at that time edited data to update the new parent node. pls clarify my issues... https://codesandbox.io/s/practical-goldberg-5g7nl my link – Saranya S Jan 04 '21 at 07:15
-
Update Tree Node Cannot Work Properly... New data to add well into parent... kindly help to clear that error... my live link... https://codesandbox.io/s/priceless-glitter-himr8?file=/src – Saranya S Jan 06 '21 at 07:14