i have tree array of nested objects. Depending on the type of element I want to give it the necessary icon.
const treeData = [
{
id: 1,
type: "FOLDER",
children: [
{
id: 2,
type: "FILE"
},
{
id: 2,
type: "FOLDER",
children: []
},
]
}
]
Unlimited number of nesting possible in folders. Output should be like that.
const treeData = [
{
id: 1,
type: "FOLDER",
icon: "folder-icon"
children: [
{
id: 2,
type: "FILE",
icon: "file-icon"
},
{
id: 2,
type: "FOLDER",
children: []
icon: "file-icon"
},
]
}
]
As i understand i should use recursive map function with CHILDREN check. But i can't reach the proper result.
icon : folder-iconnoticon: file-icon