Overview
useFetchCommentsByUserIdWrapper is a stateful wrapper around useFetchCommentsByUserId that manages the list, the cursor and the sort for a user’s comment history — for example, the comments tab of a profile page.
The hook doesn’t fetch until userId is set. Changing the sort, or any prop, resets the list and fetches from the start. See Fetch Comments by User for which comments the list contains.
Usage Example
Parameters
string | null | undefined
required
The user whose comments to list.
string | null
Only comments on this entity.
string | null
Only comments on entities with this
sourceId."exclude" | "include-outbound-blocked" | null
Server default
"exclude". "include-outbound-blocked" re-includes comments by users the signed-in user blocked, marked isAuthorBlocked: true.number
Comments per page. Default:
10.CommentIncludeParam
Related data to populate:
"user", "entity", "space", "parent", "grants".CommentsSortByOptions
Initial sort:
"createdAt", "top" or "controversial". Default: "createdAt"."asc" | "desc"
Initial sort direction; applies to every sort. Default:
"desc".ReactionType
With
sortBy: "top": the reaction to rank by. Server default: "upvote".spaceReputation, spaceReputationId, spaceReputationDescendants) are accepted too — see Reputation.
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 userId is first set. When userId is removed after it 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.
