I am new to react, I have tried to create a nested tree of folders and files of recursion. I have created 03 components Tree, Folder, and File. In the tree I have put the logic of recursion I map all the elements if I find a folder I create the folder and recall the function if I find a file I display it directly (see code below).
The function creates the level 0 elements only. I wonder why once I recall again the function Tree <Tree tree ={item.items}/>
inside the folder it does function. Any hint?
export function Tree ({tree}) {
const items = tree
return (
<>
{items.map((item, idx) => {
if (item.items) {
/**
* is Folder
*/
return (
<Folder key={idx} folder_name={item.name} num_folders={items.length} >
{<Tree tree ={item.items}/> /**this does not work**/}
</Folder>
)
}
else {
return (
<File key={idx} file_name= {item.name} file_icon={item.icon} file_size ={item.size} />
)
}
})}
</>
);
}