Get it
/
399
Sponsor

Comment Box

A ready-made comment thread for React built on Tiptap and shadcn/ui, with a rich text composer, replies, @mentions and emoji reactions. Install it with one command.

A comment thread with avatars, relative times, emoji reactions, YouTube-style replies and a composer built on the editor. Replies are one level deep and collapse under each comment; replying to a reply adds to the same thread and starts with an @mention. People can copy any comment and delete their own.

Open in new tab

Comments

5
  • ML
    Maya Lindqvist

    The new toolbar feels much lighter. Can we get a table shortcut in the next release?

  • DO
    Daniel Ortiz

    Agreed. I'd also love Mod+Shift+T to insert a 3×3 table so we skip the dialog.

  • PR
    Priya Raman

    Added it to the roadmap. I'll share a draft by Friday.

Installation

$ pnpm dlx shadcn@latest add "https://www.rtecn.space/r/comment-box.json"

The CLI also installs the Mention extension and the Static Renderer, which displays posted comments. Your project needs Tailwind CSS and shadcn/ui; see the template requirements.

Usage

Each callback fires after the change shows on screen, so you can save it to your backend. onPost receives the parent comment's id when the new comment is a reply. Return the id your backend saved the comment under (or a promise of it). Replies, reactions and deletes on that comment then receive the saved id, and any made while it is still saving wait for it. If onPost throws or rejects, the comment is removed and its text stays in the composer so the person can try again.

import { CommentBox } from "@/components/templates/comment-box";
 
export const Comments = ({ comments, user }) => (
  <CommentBox
    currentUser={{ avatar: user.image, id: user.id, name: user.name }}
    initialComments={comments}
    onPost={async (content, parentId) => {
      const saved = await saveComment({ content, parentId });
      return saved.id;
    }}
    onReact={(id, emoji) => toggleReaction(id, emoji)}
    onDelete={(id) => deleteComment(id)}
  />
);

Comments are stored as Tiptap JSON, so save content as it comes and pass it back in initialComments.

Props

PropTypeDescription
currentUserCommentAuthorThe person writing
initialCommentsCommentItem[]Comments with optional replies
onPostfunctionGets (content, parentId?), can return the saved id
onReactfunctionGets (id, emoji)
onDeletefunctionGets the deleted comment id
titlestringHeader title, default Comments
placeholderstringComposer placeholder
classNamestringOuter container classes

More templates