Loading...
Preparing your page. This should only take a moment.
Loading...
Preparing your page. This should only take a moment.

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.
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:
const comments = [ { id: 1, text: 'Hello, how are you?', children: [] }, { id: 2, text: 'I am fine, thank you!', children: [ { id: 3, text: 'I am good, thank you!', children: [] } ] } ];
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.