Replies: 1 comment
-
Hmm, I changed the the way I was adding the children in that example, and now it only shows the last child. If the parent has 4 children, the first 3 won't appear on the tree. This problem is most likely because I'm trying to request multiple times instead of just once. If 'onMissingItems' had an array with all missing children of that parent, I would just have to make one request and update the 'tree' state variable once. How do I get the missing children item ids in one go? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm having trouble trying to implement a lazy loading tree.
I followed the example on https://rct.lukasbach.com/docs/guides/controlled-environment#lazy-loading-items, but when clicking on an item with children that previously weren't in the tree structure, it tries to expand before they were even inside the tree structure, resulting in not rendering the children items at all.
By the time it adds those children to the tree structure, it no longer works even though I try to collapse the parent and expand it once again. I check React Dev Tools and the component does indeed have the items in its props, but it seems that it's not able to render them.
Here's an example program: https://codesandbox.io/s/react-complex-tree-playground-forked-0s2w2
Is there something that I'm missing? Or is my implementation completely wrong to begin with and I should be using other props/functions?
Another question, why is 'onMissingItems' returning an array with just one element? Shouldn't it have all of that parent's children that are not on the tree structure? Right now, if the parent has 2 or more children that are not on the tree structure, the method runs multiple times. I would like to make just one request, not multiple.
By the way, does the parent really need to have 'hasChildren: true' and 'children: ["a", "b", "c"]' at the time of showing the item for it to show the arrow and to trigger the 'onMissingItems'? When clicking on a parent, can't we render the children right away and then fetch their information from the server and re-render with updated information about their respective 'hasChildren' and 'children' properties?
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions