Delete a comment

Delete a comment in Bitsocial React Hooks. Usage, options, and examples.

You can remove comments from your local account database (local JSON export / IndexedDB state) in two ways. This only removes local account history entries; it does not delete already-published network comments.

1. Abandon a pending publish — if you just published and want to cancel before it propagates:

const { publishComment, abandonPublish } = usePublishComment(publishCommentOptions);

await publishComment();
// User changes mind — abandon the pending comment
await abandonPublish();
// Hook state returns to ready; the comment is removed from accountComments

2. Delete by index or CID — remove any of your comments (pending or published):

import { deleteComment, useAccountComments } from "@bitsocial/bitsocial-react-hooks";

// By account comment index (from usePublishComment or useAccountComment)
const { index, publishComment } = usePublishComment(publishCommentOptions);
await publishComment();
await deleteComment(index);

// By comment CID (from useAccountComments or useAccountComment)
const { accountComments } = useAccountComments();
const accountComment = accountComments[0];
await deleteComment(accountComment.cid);

Note: accountComment.index can change after deletions. If you delete a comment, indices of comments after it may shift. Prefer using commentCid when you need a stable identifier, or re-fetch accountComments after deletions.

Common cleanup pattern (remove failed UI clutter):

import { deleteComment, useAccountComments } from "@bitsocial/bitsocial-react-hooks";

const { accountComments } = useAccountComments();
const failedComments = accountComments.filter((comment) => comment.state === "failed");

for (const failedComment of failedComments) {
  // failed pending comments may not have a cid yet, so fallback to index
  await deleteComment(failedComment.cid || failedComment.index);
}