I have a tree-view build out of NavLinks. I've implemented both selection and open/close. It gets rendered recursively from a nested JSON source. Everything works fine.
I added a button to append new items to the tree. It recursively rebuilds the data tree and checks if the "path" where it is at matches the "path" that's currently selected, and returns a new array of child elements with the new element at the end. This also works fine.
The problem is that when I call setJsonData (from the state hook) on this rebuilt tree, the NavLink components don't show the new items. But if I "close" the right one and then "open" it again, the item shows up correctly.
Additionally, adding a new item closes other parts of the NavLink tree for whatever reason.
Both the JSON objects and the NavLinks have UUID keys, I have no idea what I'm doing wrong. This feels like I'm not managing my state updates properly but I'm quite new to Javascript and even more so to React so I really need some help.
EDIT: it works as long as the subtree has at least one child element, it's only when going from 0 to more than 0 that it does not update without opening and closing first...