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.
Comments
5- MLMaya Lindqvist
The new toolbar feels much lighter. Can we get a table shortcut in the next release?
- DODaniel Ortiz
Agreed. I'd also love
Mod+Shift+Tto insert a 3×3 table so we skip the dialog. - PRPriya 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
| Prop | Type | Description |
|---|---|---|
currentUser | CommentAuthor | The person writing |
initialComments | CommentItem[] | Comments with optional replies |
onPost | function | Gets (content, parentId?), can return the saved id |
onReact | function | Gets (id, emoji) |
onDelete | function | Gets the deleted comment id |
title | string | Header title, default Comments |
placeholder | string | Composer placeholder |
className | string | Outer container classes |
More templates
Ready-made editor apps built on editorcn: a chat composer, a document editor, a blog post editor, and a Notion-style notes workspace. Install them with the shadcn CLI.