UniqueUI

Nested Comments

Threaded comment section with infinite nesting, animated expand/collapse, inline reply composer, and spring-physics like button.

npx uniqueui add nested-comments

Preview

3 Comments
⌘+Enter to post
AK
Alex Kim2 hours ago

This component is incredible! The spring animations feel so natural and snappy.

SC
Sarah Chen1 hour agoreply

Agreed! The collapse animation is especially smooth. Love the thread lines too.

AK
Alex Kim45 min agoreply

Thanks! Motion.dev's layout animations make nested content effortless to build.

JL
Jordan Lee3 hours ago

Love the inline reply box with ⌘+Enter shortcut. Very intuitive UX — try clicking Reply!

MP
Maya Patel4 hours ago

The like button spring animation is a nice touch. Small details make a big difference.

Usage

import { NestedComments } from "@/components/ui/nested-comments";
import type { Comment } from "@/components/ui/nested-comments";

const comments: Comment[] = [
  {
    id: "1",
    author: "Alex Kim",
    content: "This component is incredible! The animations feel so natural.",
    timestamp: "2 hours ago",
    likes: 14,
    replies: [
      {
        id: "1-1",
        author: "Sarah Chen",
        content: "Agreed! The collapse animation is especially smooth.",
        timestamp: "1 hour ago",
        likes: 6,
        replies: [
          {
            id: "1-1-1",
            author: "Alex Kim",
            content: "Thanks! Motion.dev's layout animations make it effortless.",
            timestamp: "45 min ago",
            likes: 3,
          },
        ],
      },
    ],
  },
  {
    id: "2",
    author: "Jordan Lee",
    content: "Love the inline reply box with keyboard shortcuts. Very intuitive UX.",
    timestamp: "3 hours ago",
    likes: 9,
  },
];

export default function Example() {
  return (
    <div className="p-6 bg-neutral-950 rounded-xl min-h-[400px]">
      <NestedComments
        comments={comments}
        maxDepth={4}
        accentColor="#8b5cf6"
        onReply={(id, content) => console.log("Reply to", id, ":", content)}
        onLike={(id) => console.log("Liked", id)}
      />
    </div>
  );
}

Props

PropTypeDescription
commentsComment[]Array of top-level comment objects, each optionally containing a `replies` array for nested threading.
maxDepthnumberMaximum nesting depth allowed before disabling the Reply button to prevent infinite threading.
classNamestringAdditional CSS classes applied to the root wrapper element.
accentColorstringHex or CSS color used for reply badge highlights and interactive accent elements.
onReply(commentId: string, content: string) => voidCallback fired when a user submits a reply, receiving the parent comment ID and reply text.
onLike(commentId: string) => voidCallback fired when a user likes a comment, receiving the comment ID.