File Tree Explorer
Build a collapsible file tree (like VS Code's sidebar). Folders expand/collapse on click. Users can add files or folders inside any folder, and delete any node.
Requirements
- Render a nested tree of folders and files
- Click a folder to toggle expand/collapse
- Add a file or folder inside any folder (prompt for name)
- Delete any file or folder (deleting a folder removes its children too)
- Show appropriate icons: π (closed folder), π (open folder), π (file)
- Indent child nodes by depth level
Key Patterns
Recursive component (TreeNode renders itself)useReducer for tree stateRecursive immutable tree updatemap() to update a node by IDfilter() to delete a node by ID
Important
Interview Tip
The key insight: tree state updates are recursive. Write helper functions β toggleNode(tree, id), addNode(tree, parentId, newNode), deleteNode(tree, id) β each using map/filter recursively. Using useReducer keeps the component clean: dispatch({ type: "TOGGLE", id }) instead of inline logic.
π my-project β hover a row to see actions
πsrc
πcomponents
πButton.tsx
πInput.tsx
πpages
πApp.tsx
πindex.ts
πpackage.json
πtsconfig.json