Loading problem…
Build a File Explorer component in React that displays a hierarchical file/folder structure. Users should be able to expand/collapse folders and select files or folders.
interface FileNode {
id: number;
name: string;
type: 'file' | 'folder';
children?: FileNode[];
}
interface FileExplorerProps {
data: FileNode[];
}> Note: Use semantic HTML elements like <ul> and <li> for the tree structure. Avoid inline styles and use CSS classes instead.
Here's an example of the data structure you'll be working with:
const exampleData: FileNode[] = [
{
id: 1,
name: 'src',
type: 'folder',
children: [
{
id: 2,
name: 'components',
type: 'folder',
children: [
{ id: 3, name: 'Button.tsx', type: 'file' },
{ id: 4, name: 'Card.tsx', type: 'file' },
],
},
{ id: 5, name: 'App.tsx', type: 'file' },
],
},
{
id: 6,
name: 'package.json',
type: 'file',
},
];