I have the below code:
<TreeView
aria-label="controlled"
defaultCollapseIcon={<ExpandMoreIcon />}
defaultExpandIcon={<ChevronLeftIcon />}
expanded={expanded}
selected={selected}
onNodeToggle={handleToggle}
onNodeSelect={handleSelect}
multiSelect
>
{
rows.data.map((item: IPTreeModel)=> {
return (
<TreeItem nodeId={item.id} label={item.subnet} onClick={item.has_child ? (e: MouseEvent)=> loadChildren(e, item.subnet) : ()=> ''}>
{/*here*/}
</TreeItem>
)
})
}
</TreeView>
And below is my function:
const loadChildren = (e: MouseEvent, id: number | string) => {
// fetch new data based on the ID parameter, and append the output as a TreeItem element.
}
Now I need to append a new <TreeItem> element to the last <TreeItem> in case user clicks on loadChildren function.
How is the react way of doing this?
