Skip to main content

Overview

useReplies gives you a comment’s replies inside the nearest CommentSectionProvider, and a loadMore function that continues from whatever is already loaded — including replies the section brought in nested with the first page. It never fetches on its own: call loadMore() (for example from a “View replies” button).
Must be used inside a CommentSectionProvider. See Comment Section.

Usage Example

The same component works whether or not the section nests replies: with the provider’s replyDepth above 0, comments arrive with their first replies already loaded; with the default replyDepth of 0, every comment starts with nothing loaded and the first click fetches its replies.

What a load fetches

The first load of a comment’s replies nests, using the section’s replyDepth and replyLimit. Later loads fetch plain pages. Every load continues after the replies already shown — including ones the section pre-loaded. With the provider at replyDepth={2} replyLimit={3} and useReplies({ limit: 10 }): You can override the rule for a thread or for a single click:
Replies are always sorted by the section’s reply sort (the provider’s replySortBy / replySortDir / replySortByReaction, which default to the section’s sort), so loading more continues in the same order as the pre-loaded replies. A request can return at most 500 comments (see Request size limit). If the default first-load nesting would go over it, useReplies lowers the depth until it fits and logs a warning in development. A replyDepth you pass explicitly is sent as-is.

Props

string
required
The ID of the comment whose replies to load.
number
How many direct replies each load fetches. Default: 10. Can be overridden per call with loadMore({ limit }).
number
Levels of replies to nest on this comment’s first load (0–5). Defaults to the section’s replyDepth. Later loads don’t nest unless you pass loadMore({ replyDepth }).

Return Values

Comment | undefined
The comment itself, from the section, once it’s loaded.
Comment[]
Its loaded replies, in order. Replies the user posted this session are kept out of this list (they’re in newReplies), even if a later load returns them.
Comment[]
Replies the user posted this session, newest first. They stay where they are rather than jumping into replies.
boolean
true while a load of this commentId’s replies is in flight. It belongs to the commentId passed: a load still running for another comment doesn’t show here.
Error | null
The last failure loading this commentId’s replies; a failure for another comment doesn’t show here. Cleared when the next load starts or the section resets (for example on a sort change). Call loadMore() to retry — hasMore stays true after a failure, and the retry asks for the same replies again (including the nesting of a first load).
boolean
Whether there are replies to load. Before the comment’s replies were ever loaded, this is true when its repliesCount is more than the replies already shown under it — the user’s own new replies and, for the parent of a highlighted comment, the highlighted reply. After that, it’s the server’s exact hasMore.
(options?: { replyDepth?: number; limit?: number }) => Promise<void>
Loads the next replies, or retries the load that failed. Does nothing while a load is in flight or when hasMore is false, and never throws — failures land in error.