Create a post or comment using hooks
Create a post or comment using hooks in Bitsocial React Hooks. Usage, options, and examples.
const publishCommentOptions = {
content: "hello",
title: "hello",
communityAddress: "12D3KooW...",
};
const {
index,
state,
publishComment,
challenge,
challengeVerification,
publishChallengeAnswers,
abandonPublish,
error,
} = usePublishComment(publishCommentOptions);
if (challenge) {
// display challenge.challenges and call publishChallengeAnswers(challengeAnswers)
}
if (challengeVerification) {
// display challengeVerification.challengeSuccess to user
// on success, redirect once challengeVerification.commentUpdate?.cid is defined
}
if (error) {
// display error to user
}
// if the user closes your challenge modal:
if (challenge && challengeModalClosedByUser) {
await abandonPublish();
}
// after publishComment is called, the account comment index gets defined
// it is recommended to immediately redirect the user to a page displaying
// the user's comment with a "pending" label
if (index !== undefined) {
history.push(`/profile/c/${index}`);
// on the "pending" comment page, you can get the pending comment by doing
// const accountComment = useAccountComment({commentIndex: index})
// after accountComment.cid gets defined, it means the comment was published successfully
// it is recommended to immediately redirect to `/p/${accountComment.communityAddress}/c/${useAccountComment.cid}`
}
// create post
await publishComment();