API reference
MarkdownSource

Comments Hooks

Comments Hooks in Bitsocial React Hooks. Usage, options, and examples.

useComment({commentCid: string, community?: CommunityIdentifier, initialComment?: Comment, onlyIfCached?: boolean, autoUpdate?: boolean}): Comment & {refresh: Function}
useCrosspost({crosspost: Crosspost, autoUpdate?: boolean}): Comment & {isCommunityVerified: boolean, refresh: Function}
useReplies({comment: Comment, onlyIfCached?: boolean, sortType?: string, flat?: boolean, repliesPerPage?: number, filter?: CommentsFilter, accountComments?: {newerThan: number, append?: boolean, limit?: number}}): {replies: Comment[], hasMore: boolean, loadMore: function, reset: function, updatedReplies: Comment[], bufferedReplies: Comment[], sortTypeUnavailable: boolean}
useComments({commentCids: string[], onlyIfCached?: boolean, autoUpdate?: boolean}): {comments: Comment[], refresh: Function}
useEditedComment({comment: Comment}): {editedComment: Comment | undefined}
useValidateComment({comment: Comment, validateReplies?: boolean}): {valid: boolean}

useComment().state is failed when the comment’s last load failed and nothing loaded since: pkc-js reported failed for a non-retriable error such as an invalid signature, comment.update() rejected, or the comment could not be created, for example because pkc.createComment threw. It stays failed through the stopped that follows when the failed comment is stopped, and while pkc-js retries a failed CommentUpdate at the community’s next update, until a load succeeds. A comment that already has a CommentUpdate (updatedAt) stays succeeded when a later update fails, and a comment published less than 5 minutes ago is failed instead of succeeded when its load failed. The account’s own published comment, shown from the account (it has an index), never becomes failed from a failed load, because failed with an index means its publication failed. Retriable errors, such as a gateway timeout, keep the loading state and only add to errors. useComments().state is failed once none of its comments is still loading and at least one failed; error and errors then hold the errors of the comments that failed, and stay empty otherwise.