Overview
useEntityComments is a lower-level hook that fetches and manages a paginated comment tree for a given entity ID. It is used internally by CommentSectionProvider. Use it directly when you need comment tree management without the full provider.
For most use cases, use
CommentSectionProvider + useCommentSection instead. See Comment Section.Usage Example
Props
string | null | undefined
required
The entity ID to fetch comments for.
number
Comments per page. Default:
10.string
Initial sort:
"createdAt", "top", or "controversial". Default: "createdAt". "new"/"old" are deprecated aliases for "createdAt" (removed in v8)."asc" | "desc"
Initial sort direction for
sortBy: "createdAt". Default: "desc" (newest first).string | string[]
Populate related data. Accepted values:
"user", "entity", "space", "parent".Return Values
EntityCommentsTree
Flat map of all comments and their replies, keyed by comment ID.
Comment[]
Paginated root-level comments (not newly added ones).
Comment[]
Newly added root comments from this session, sorted newest-first.
boolean
true during fetches.boolean
true when more pages are available.CommentsSortByOptions | null
Current sort order.
(newSortBy: CommentsSortByOptions) => void
Changes sort order and resets to page 1.
"asc" | "desc"
Current sort direction for
sortBy: "createdAt".(newSortDir: "asc" | "desc") => void
Changes sort direction and resets to page 1.
() => void
Loads the next page.
(comments?: Comment[], newlyAdded?: boolean) => void
Inserts comments into the tree. Pass
newlyAdded: true for freshly submitted comments.({ commentId }) => void
Removes a comment from the tree.
({ commentId }) => void
Marks a comment as deleted (Reddit-style placeholder) without removing it from the tree.

