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).
The list starts over from the first page when the signed-in user signs in, signs out or switches accounts, since each comment carries that user’s own reaction (userReaction).
For most use cases, use
CommentSectionProvider + useCommentSection instead. See Comment Section. Replies loaded through useReplies require the provider.Usage Example
Props
The entity whose comments to load. Nothing is fetched until it’s set.
Initial sort:
"createdAt", "top" or "controversial". Default: "createdAt". Changeable at runtime with setSortBy.Initial sort direction for
"createdAt" and "top"; ignored (not sent) for "controversial", which ranks one way only. Default: "desc". Changeable with setSortDir.The reaction
"top" ranks by (raw count). Server default: "upvote". Changeable with setSortByReaction.Levels of replies to nest under every top-level comment, on every page (
0–5). Default: 0 — replies load on demand through useReplies.Sort for replies:
"createdAt", "top" or "controversial". Defaults to the current sort. Not changeable at runtime.Sort direction for replies. Defaults to the current sort direction (
"desc" while the section sorts by "controversial"); not sent when the reply sort is "controversial". Not changeable at runtime.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.Related data to populate, at every level.
"files" adds the comment’s images and files (requires the files-images bundle). Default: "user".limit, replyDepth and replyLimit as given; a combination over the limit fails with an error in error, and outside production builds (in development and in test runs) the SDK logs which values to lower.
Return Values
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).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.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. A SublayError.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.Reloads the top-level comments from the first page with the current sort. The loaded comments stay until the new first page replaces them; after it lands, the section still holds the viewer’s own new comments and replies, the highlighted comment, and the reply pages loaded under comments that are still listed (with their place, so loading more replies continues from there). Top-level comments that are not on the new first page are dropped. Never throws — failures land in
error, and loadMore() retries.A loaded comment by ID — top-level or a reply — without its nested
replies.
