Skip to main content

Overview

useFetchManyCommentsWrapper is a stateful wrapper around useFetchManyComments that manages the list, the cursor and the sort for you. It lists one level of a thread: an entity’s top-level comments (entityId) or a comment’s direct replies (parentId). Use it for a custom thread view outside CommentSectionProvider. The hook doesn’t fetch until entityId or parentId is set. Changing the sort, or any prop, resets the list and fetches from the start. Nested replies (replyDepth above 0) come back inside each comment’s replies exactly as the server delivers them — the hook doesn’t track them. For per-comment “load more replies”, use CommentSectionProvider with useReplies. For a user’s comments across entities, use useFetchCommentsByUserIdWrapper.

Usage Example

Parameters

string | null
List this entity’s top-level comments.
string | null
List this comment’s direct replies. With both set, parentId decides the level and entityId must match the parent’s entity — otherwise the list is empty.
number
Comments per page. Default: 10.
CommentsSortByOptions
Initial sort: "createdAt", "top" or "controversial". Default: "createdAt". "new" / "old" are deprecated aliases for "createdAt".
"asc" | "desc"
Initial sort direction; applies to every sort. Default: "desc".
ReactionType
With sortBy: "top": the reaction to rank by (raw count). Server default: "upvote".
"user" | "grants" | ("user" | "grants")[]
Related data to populate, at every level.
number
Levels of replies to nest under each comment (0–5). Server default: 0.
number
Replies per comment in the nested levels. Server default: 3.
CommentReplySortByOptions
Sort for the nested levels. Defaults to the current sort.
"asc" | "desc"
Sort direction for the nested levels. Defaults to the current direction.
ReactionType
The reaction the nested levels rank by, when their sort is "top".

Returns

Comment[]
The fetched comments. Each loadMore appends the next page; a comment already in the list isn’t added twice.
boolean
true while a page is loading, and before entityId or parentId is first set. When both are removed after one was set, the list is cleared and loading is false.
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 comments are available.
() => Promise<void>
Loads the next page, 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.
CommentsSortByOptions
Current sort.
(sortBy: CommentsSortByOptions) => void
Changes the sort and reloads from the start.
"asc" | "desc"
Current sort direction.
(sortDir: "asc" | "desc") => void
Changes the sort direction and reloads from the start.
ReactionType | undefined
The reaction "top" ranks by. Only sent with sortBy: "top".
(reaction: ReactionType | undefined) => void
Changes the ranking reaction. While sortBy is "top" this reloads from the start; under any other sort the value is kept for later and nothing reloads.