Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh tree after adding element #611

Open
kortirso opened this issue Dec 16, 2019 · 6 comments
Open

Refresh tree after adding element #611

kortirso opened this issue Dec 16, 2019 · 6 comments

Comments

@kortirso
Copy link

Hi, I used
<SortableTree treeData={treeData} ... >
and I have situations when treeData is changed after adding new elements in tree
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?

@bamne123
Copy link

Did Anyone find solution?

@mkamalkayani
Copy link

The state might be getting mutated which prevents rerender. If the state is not mutated than React will handle the rerender.

@goldenjayr
Copy link

does anyone has a solution on this??

@nestorovicevo
Copy link

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]); };

@nestorovicevo
Copy link

does anyone has a solution on this??

Maybe this can help you

@seancheno
Copy link

setTreeData([...result]) did the trick for me. Spent too much time trying to figure out the issue so thank you very much nestorovicevo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants