Get a post

Get a post in Bitsocial React Hooks. Usage, options, and examples.

const post = useComment({ commentCid, community: { name: communityAddress, publicKey: communityPublicKey } });

// manual refresh is always available
await post.refresh();

// post.author.address should not be used directly, it needs to be verified asynchronously using useAuthorAddress
const { authorAddress, shortAuthorAddress } = useAuthorAddress({ comment: post });
// exception: when linking to an author profile page, /u/${comment.author.address}/c/${comment.cid} should be used, not useAuthorAddress({comment}).authorAddress

// use many times in a page without affecting performance
const post = useComment({ commentCid, onlyIfCached: true });

// disable background polling and refresh on demand
const post = useComment({ commentCid, autoUpdate: false });
// the initial load includes the first community update (including moderation)
// before freezing; a recent creation timestamp alone does not settle the snapshot
// resolves after one update cycle, also when no newer CommentUpdate exists, and right
// away when another instance (e.g. your own reply) already keeps the comment updating
await post.refresh();
// newly published comments still absorb canonical number, postNumber, and
// author shortAddress metadata as it arrives; later live updates stay frozen

// post.replies are not validated, to show replies
const { replies, hasMore, loadMore } = useReplies({ comment: post });

// only use the comment's preloaded replies plus any reply pages already cached in memory
// won't fetch missing reply pages; hasMore only reflects cached replies still available to load
const cachedReplies = useReplies({ comment: post, onlyIfCached: true });

// to show a preloaded reply without rerenders, validate manually
const { valid } = useValidateComment({ comment: post.replies.pages.best.comments[0] });
if (valid === false) {
  // don't show this reply, it's malicious
}
// won't cause any rerenders if true