Loading problem…
Build a Comments Thread component in React that renders nested replies and supports branch-level interactions (reply, collapse/expand) without corrupting tree state.
root -> replies -> deeper replies).comment.id (never array index).push/splice on existing state).interface CommentNode {
id: string;
author: string;
body: string;
createdAt: string;
replies?: CommentNode[];
}
interface CommentsThreadProps {
comments: CommentNode[];
onChange: (next: CommentNode[]) => void;
}const seed: CommentNode[] = [
{
id: "c1",
author: "Ava",
body: "Great write-up.",
createdAt: "2026-04-01T09:00:00.000Z",
replies: [
{
id: "c1-1",
author: "Noah",
body: "Agreed, especially the caching part.",
createdAt: "2026-04-01T09:05:00.000Z"
}
]
}
];