Hi, I used
state with treeData is changed but SortableTree is not updated, I can see new elements only after any actions with SortableTree like dragging.
Is there way to refresh SortableTree after some actions not in SortableTree?
Did Anyone find solution?
The state might be getting mutated which prevents rerender. If the state is not mutated than React will handle the rerender.
does anyone has a solution on this??
I found the solution by inserting spread. For example, code before was:
const addCategory = async (node, lowerSiblingCounts) => { const route = lowerSiblingCounts.slice(0, lowerSiblingCounts.length - 1); const result = await updatingTree(node, treeData, route, 0); setTreeData(result); };
And now it's:
const addCategory = async (node, lowerSiblingCounts) => { const route = lowerSiblingCounts.slice(0, lowerSiblingCounts.length - 1); const result = await updatingTree(node, treeData, route, 0); setTreeData([...result]); };
does anyone has a solution on this??
Maybe this can help you
setTreeData([...result]) did the trick for me. Spent too much time trying to figure out the issue so thank you very much nestorovicevo!
Most helpful comment
I found the solution by inserting spread. For example, code before was:
const addCategory = async (node, lowerSiblingCounts) => { const route = lowerSiblingCounts.slice(0, lowerSiblingCounts.length - 1); const result = await updatingTree(node, treeData, route, 0); setTreeData(result); };
And now it's:
const addCategory = async (node, lowerSiblingCounts) => { const route = lowerSiblingCounts.slice(0, lowerSiblingCounts.length - 1); const result = await updatingTree(node, treeData, route, 0); setTreeData([...result]); };