I have a simple tree with React, the tree has its data from the root Node and it renders its children recursively -
<div className="Tree">
<div>{props.name}</div>
<div className="children">
{props.children &&
props.children.map((item) => {
return <TreeNode name={item.name} children={item.children} />;
})}
</div>
</div>
By Changing the TreeNode component and using useState how could I make an option for an action of add child to any node in the tree ?
Here is the code I have so far - Demo
(You can implement the action of add child in the button there and give the new child any name you want)