Overview
useEntityComments is a lower-level hook that loads an entity’s top-level comments, cursor-paginated, with optional nested replies. It is used internally by CommentSectionProvider. Use it directly when you need the comment list without the rest of the provider (reply state, comment creation, highlighted comments).
For most use cases, use
CommentSectionProvider + useCommentSection instead. See Comment Section. Replies loaded through useReplies require the provider.Usage Example
Props
string | null | undefined
required
The entity whose comments to load. Nothing is fetched until it’s set.
number
Top-level comments per page. Default:
10.CommentsSortByOptions
Initial sort:
"createdAt", "top" or "controversial". Default: "createdAt". Changeable at runtime with setSortBy. "new" / "old" are deprecated aliases for "createdAt"."asc" | "desc"
Initial sort direction; applies to every sort. Default:
"desc". Changeable with setSortDir.ReactionType
The reaction
"top" ranks by (raw count). Server default: "upvote". Changeable with setSortByReaction.number
Levels of replies to nest under every top-level comment, on every page (
0–5). Default: 0 — replies load on demand through useReplies.number
Replies per comment in the nested levels. Default:
3.CommentReplySortByOptions
Sort for replies:
"createdAt", "top" or "controversial". Defaults to the current sort. Not changeable at runtime."asc" | "desc"
Sort direction for replies. Defaults to the current sort direction. Not changeable at runtime.
ReactionType
The reaction replies rank by when their sort is
"top". Defaults to the current sortByReaction when the section is also sorted by "top", else "upvote". Not changeable at runtime."user" | "grants" | ("user" | "grants")[]
Related data to populate, at every level. Default:
"user".limit, replyDepth and replyLimit as given; a combination over the limit fails with an error in error, and a development build logs which values to lower.
Return Values
Comment[]
Loaded top-level comments, in sort order (not including ones added this session).
Comment[]
Always empty when the hook is used on its own: it has no way to add a comment. Inside
CommentSectionProvider the same field holds the top-level comments posted this session (see useCommentSection).boolean
true while a page is loading, and while entityId isn’t set. When entityId changes, comments is empty and loading is true from the first render with the new id.Error | null
The last failure loading the list. Cleared when the next load starts. Call
loadMore() to retry — hasMore stays true after a failure, and the retry asks for the same page again, including a first page that failed.boolean
true when more top-level comments are available.() => Promise<void>
Loads the next page of top-level comments, or retries the page that failed. Does nothing while a page is loading or when
hasMore is false, and never throws — failures land in error.(commentId: string) => Comment | undefined
A loaded comment by ID — top-level or a reply — without its nested
replies.CommentsSortByOptions
Current sort.
(newSortBy: CommentsSortByOptions) => void
Changes the sort and reloads from the first page.
"asc" | "desc"
Current sort direction.
(newSortDir: "asc" | "desc") => void
Changes the sort direction and reloads from the first page.
ReactionType | undefined
The reaction
"top" ranks by. Only sent with sortBy: "top".(newReaction: ReactionType | undefined) => void
Changes the ranking reaction. While
sortBy is "top" this reloads from the first page; under any other sort the value is kept for later and nothing reloads.
