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
):
null`
null`
null`
null`
null`
The number of comments to fetch per page. Default is
15
.The default sorting criteria for comments (e.g.,
new
, top
).Optional callbacks for handling events like login requirements.
No
Returns
The hook returns an object with the following fields:undefined \
undefined`
Tree structure representing threaded comments.
The list of root-level comments currently loaded.
Comments that were recently added during the session.
null } \
Indicates if comments are currently loading.
Whether there are more comments available for pagination.
Whether a comment is currently being submitted.
Loads the next page of comments.
null`
Updates the comment sort order.
null`
null`
null) => void`
null`
null) => void`
Whether the UI banner indicating a reply is visible.
Controls the reply banner visibility.
undefined, newlyAdded?: boolean) => void`
Removes a comment from the tree structure.
Handles a shallow reply (mention-only, not nested).
Handles a deep reply (visibly nested under the parent comment).
createComment
(props: { parentId?: string; content?: string; gif?: GifData; mentions: Mention[] }) => Promise<void>
Submits a new comment. Includes temporary rendering and error fallback.
Updates an existing comment.
Deletes a comment from both the UI and backend.