CommentSectionProvider loads and manages all comment state for a given entity. Descendant components access this state through useCommentSection.
Setting Up CommentSectionProvider
Identify the target entity with one of four mutually exclusive props:Provider Props Reference
Replyke entity ID. Mutually exclusive with
foreignId, shortId, and entity.Your system’s ID for the entity.
Auto-generated short ID.
A pre-fetched entity object. Skips the entity fetch.
Only valid with
foreignId. Auto-creates the entity if it doesn’t exist yet.Comments per page. Default:
15.Initial sort order:
"top" (default), "new", or "controversial".If provided, fetches this comment and its parent and injects it into the tree. Useful for deep-linking to a specific comment.
Optional callback functions for handling UI interactions:
loginRequiredCallback()— called when a non-authenticated user tries to commentusernameRequiredCallback()— called when the user has no username setcommentTooShortCallback()— called when the submitted comment is too short
Override the trigger characters for mentions. Defaults:
{ user: "@", space: "#" }.Accessing State with useCommentSection
useCommentSection Return Values
The entity these comments belong to.
Paginated root-level comments (not newly submitted ones).
Comments submitted in this session. Displayed separately from paginated results, sorted newest-first.
The full comment tree as a flat map keyed by comment ID. Used for building threaded reply UIs.
The highlighted comment (and its parent, if any) when
highlightedCommentId is set.true while the initial comment load is in progress.true when more pages are available.true while a createComment call is in flight.Loads the next page of comments.
Current sort:
"top", "new", or "controversial".Changes the sort order and resets to page 1.
Submits a new comment. Applies an optimistic placeholder immediately. Accepts:
parentId— reply to a specific comment IDcontent— text contentgif— GIF data objectmentions— array ofMentionobjectsautoReaction— automatically react with this reaction type after creating (e.g."upvote")
Updates a comment’s text content.
Marks a comment as deleted (Reddit-style placeholder). The comment remains in the tree with its content hidden.
Currently selected/focused comment. Managed via
setSelectedComment.Set or clear the selected comment.
The comment currently being replied to.
Set the comment to reply to.
Whether to show a reply indicator UI banner.
Show or hide the reply banner.
A user to auto-insert as a mention in the next comment. Set by
handleShallowReply.Sets the reply target for a deep reply (reply appears nested under the parent comment).
Sets the reply target for a shallow reply (reply appears at root level with an
@mention).
