useCommentSectionData
Overview
TheuseCommentSectionData hook provides a comprehensive solution for managing comment sections associated with entities. Unlike individual hooks such as useFetchComments or useCreateComment, this hook combines functionalities like fetching, creating, updating, deleting, and managing comment states (e.g., sorting, replying). It is ideal for implementing fully-featured comment sections with advanced state management.
Usage Example
Parameters & Returns
Parameters
The hook accepts an object with the fields below. At least one of the first 4 fields must be provided (entityId/foreignId/shortId/entity):
string \
null`
string \
null`
string \
null`
Entity \
null`
string \
null`
number
The number of comments to fetch per page. Default is
15.CommentsSortByOptions
The default sorting criteria for comments (e.g.,
new, top).SocialStyleCallbacks
Optional callbacks for handling events like login requirements.
string \
No
Returns
The hook returns an object with the following fields:Entity \
undefined \
Record<string, (...args: any[]) => void> \
undefined`
EntityCommentsTree
Tree structure representing threaded comments.
Comment[]
The list of root-level comments currently loaded.
Comment[]
Comments that were recently added during the session.
{ comment: Comment; parentComment: Comment \
null } \
boolean
Indicates if comments are currently loading.
boolean
Whether there are more comments available for pagination.
boolean
Whether a comment is currently being submitted.
() => void
Loads the next page of comments.
CommentsSortByOptions \
null`
(newSortBy: CommentsSortByOptions) => void
Updates the comment sort order.
UserLean \
null`
Comment \
null`
(newSelectedComment: Comment \
null) => void`
Partial<Comment> \
null`
(newRepliedToComment: Comment \
null) => void`
boolean
Whether the UI banner indicating a reply is visible.
(newState: boolean) => void
Controls the reply banner visibility.
(newComments: Comment[] \
undefined, newlyAdded?: boolean) => void`
(commentId: string) => void
Removes a comment from the tree structure.
(comment: Comment) => void
Handles a shallow reply (mention-only, not nested).
(comment: Comment) => void
Handles a deep reply (visibly nested under the parent comment).
(props: { parentId?: string; content?: string; gif?: GifData; mentions: Mention[] }) => Promise<void>
Submits a new comment. Includes temporary rendering and error fallback.
(props: { commentId: string; content: string }) => Promise<void>
Updates an existing comment.
(props: { commentId: string }) => Promise<void>
Deletes a comment from both the UI and backend.

