File Explorer
Build a nested folder tree from nothing — expand, collapse, and add files and folders at any depth.
React · JavaScript — Pratik Rai ·
Build a Reddit-style nested comments system in React using recursion. Learn tree data structures, efficient state management, and how to render deeply threaded replies.

Design a component that renders a tree of comments. Each comment can have replies, and those replies can have replies (n-levels deep). There will be an option to add a new comment and also delete a comment. This is a common frontend interview question that tests your understanding of recursive components and tree data structures.
Goal: build a Reddit-style nested comments thread.
Requirements
Stretch goals
id, text, and children.Basically, we will maintain the comments as a tree of objects, where each node represents a comment and contains an array of replies.
Sample Data Structure:
JSfile.js1const comments = [ 2 { 3 id: 1, 4 text: 'Hello, how are you?', 5 children: [] 6 }, 7 { 8 id: 2, 9 text: 'I am fine, thank you!', 10 children: [ 11 { 12 id: 3, 13 text: 'I am good, thank you!', 14 children: [] 15 } 16 ] 17 } 18];
Components:
CommentListCommentThere are three main flows:
Reply Flow:
parent.children.Delete Flow:
Rendering Flow:
CommentList renders the top-level comments.Comment renders itself and recursively renders children.Goal: Implement a recursive nested comments system within 45-60 minutes. Focus on clean component structure and efficient state management.
Continue learning with these related challenges
Build a nested folder tree from nothing — expand, collapse, and add files and folders at any depth.
React · JavaScript — Pratik Rai ·
Given a flat array of items with parentId, render them as nested tabs at arbitrary depth.
React · JavaScript — Pratik Rai ·
Create an interactive image carousel in React with smooth slide transitions, navigation arrows, dot indicators, autoplay, and touch/swipe support for mobile devices.
React · JavaScript — Pratik Rai ·
Build a nested folder tree from nothing — expand, collapse, and add files and folders at any depth.
React · JavaScript
Pratik Rai ·
Given a flat array of items with parentId, render them as nested tabs at arbitrary depth.
React · JavaScript
Pratik Rai ·
Create an interactive image carousel in React with smooth slide transitions, navigation arrows, dot indicators, autoplay, and touch/swipe support for mobile devices.
React · JavaScript
Pratik Rai ·