Home
← All questions

File/Folder explorer (tree view) | Frontend Machine Coding

MediumPremiumMachine Coding

Frontend Machine Coding interview practice: Build a collapsible file/folder tree with expand/collapse and add/delete nodes.

Problem

Build a file explorer that renders a nested folder structure as a collapsible tree.

Requirements

  • Render folders and files from a nested JSON structure.
  • Click a folder to expand/collapse its children.
  • Folders show a different icon than files; only folders can contain children.
  • (Bonus) Add a new file/folder under a folder, and delete a node.
  • (Bonus) Lazy render children only when expanded.

Hints / Approach

  • Model: { name, isFolder, children: [] }. Render recursively with a Node component.
  • Keep expand state per-node (local state in each Node, or a map keyed by id in the parent).
  • For add/delete, mutate an immutable copy and lift state up, or use a reducer keyed by node id.
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium