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
Initial sort order:
"top" (default), "createdAt", or "controversial". "new"/"old" are deprecated aliases for "createdAt" (removed in v8).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
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.Current sort:
"createdAt", "top", or "controversial". ("new"/"old" are deprecated aliases for "createdAt".)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")
Marks a comment as deleted (Reddit-style placeholder). The comment remains in the tree with its content hidden.
Sets the reply target for a deep reply (reply appears nested under the parent comment).

