Requires the
comments bundle. Comments are only available when the comments bundle is installed on your project. See Bundles to add it.The Provider Pattern
The comment system uses aCommentSectionProvider + useCommentSection pair. Wrap your comment UI with CommentSectionProvider to load comments for an entity, then access all comment state and actions from any descendant with useCommentSection. Identify the entity by its entityId (or pass the entity object you already have):
foreignId, with createIfNotFound to create the entity on first load. See Link entities to records you already have.
What the Provider Manages
- Loading comments — fetches the first page of top-level comments on mount and provides
loadMore/hasMorefor the next ones (cursor-paginated, so new comments never shift what you get) - Nested replies — optionally brings a few levels of replies with every page (
replyDepth,replyLimit);useRepliesloads more for any comment, continuing from what’s already loaded - One copy of each comment — every loaded comment is kept once, so an edit or delete shows up everywhere it’s rendered; read any loaded comment with
getComment(id) - New comments — tracks freshly submitted comments separately from fetched ones, so they don’t jump around
- Highlighted comment — fetches and shows a specific comment (e.g., from a deep link)
- Reply state — tracks which comment is being replied to and shows/hides the reply banner
- CRUD actions —
createComment,updateComment,deleteCommentwith optimistic updates - Sort —
sortBy/setSortByfor switching between"createdAt","top"(raw count ofsortByReaction, default upvotes) and"controversial", plussortDir/setSortDir("asc"/"desc"), which applies to"createdAt"and"top"("controversial"always ranks most controversial first) - Errors — a failed load lands in
error;loadMorenever throws
In This Section
Comment Section
Full guide to CommentSectionProvider props and the useCommentSection hook values.
Pre-Built Comment Components
If you’d rather not wire up your own comment UI, Sublay provides two production-ready comment components installed via the CLI directly into your project as editable source code.Threaded Comments
A classic threaded comment section with nested replies, reactions, and sorting. Ideal for blogs, docs, and long-form content.
Social Comments
A flat social-style comment feed with inline replies and a familiar social media feel. Great for feeds and short-form content.
CommentSectionProvider and useCommentSection — the same primitives documented here — so you can customize them as deeply as needed after installation.

