Get a community
Get a community in Bitsocial React Hooks. Usage, options, and examples.
const community = useCommunity({ community: { name: communityAddress, publicKey: communityPublicKey } });
const {
syncState,
hasCachedData,
lastFetchAttemptAt,
lastSuccessfulFetchAt,
} = community;
const communityStats = useCommunityStats({
community: { name: communityAddress, publicKey: communityPublicKey },
});
const { communities } = useCommunities({
communities: [
{ name: communityAddress, publicKey: communityPublicKey },
{ name: communityAddress2, publicKey: communityPublicKey2 },
{ name: communityAddress3, publicKey: communityPublicKey3 },
],
});
// fetched communities are refreshed immediately and then every 15 minutes
// so long-lived tabs keep following community IPNS updates
// use without affecting performance
const { communities: cachedCommunities } = useCommunities({
communities: [
{ name: communityAddress, publicKey: communityPublicKey },
{ name: communityAddress2, publicKey: communityPublicKey2 },
{ name: communityAddress3, publicKey: communityPublicKey3 },
],
onlyIfCached: true,
});
// community.posts are not validated, to show posts
const { feed, hasMore, loadMore } = useFeed({
communities: [{ name: communityAddress, publicKey: communityPublicKey }],
});
// to show a preloaded post without rerenders, validate manually
const { valid } = useValidateComment({ comment: community.posts.pages.topAll.comments[0] });
if (valid === false) {
// don't show this post, it's malicious
}
// won't cause any rerenders if true