Trying to implement a tree view in React but struggling with constructing the hierarchical view of information.
Reference: https://www.w3schools.com/howto/howto_js_treeview.asp
Example on CodeSandbox: https://codesandbox.io/s/unruffled-babbage-9knrz?file=/index.js
JSON example (format may vary):
const data = [
{
title: "Node 1",
childNodes: [
{ title: "Childnode 1.1" },
{
title: "Childnode 1.2",
childNodes: [
{
title: "Childnode 1.2.1",
childNodes: [{ title: "Childnode 1.2.1.1" }]
},
{ title: "Childnode 1.2.2" }
]
}
]
}
];
I have a toggle function for expanding/collapsing tree nodes, but still having difficulty with building the tree in react.
Any guidance would be appreciated.