Create accounts and change active account
Create accounts and change active account in Bitsocial React Hooks. Usage, options, and examples.
import {
useAccount,
useAccounts,
createAccount,
setActiveAccount,
} from "@bitsocial/bitsocial-react-hooks";
const account = useAccount();
const { accounts } = useAccounts();
// on first render
console.log(accounts.length); // 1
console.log(account.name); // e.g. 'Account KoXpxTwfnjA5'
console.log(account.name === `Account ${account.author.shortAddress}`); // true
await createAccount(); // creates another uniquely named account
await createAccount();
const thirdAccountName = accounts[2].name;
await setActiveAccount(thirdAccountName);
// on render after updates
console.log(accounts.length); // 3
console.log(account.name); // thirdAccountName
// you are now publishing from the third account because it is active
const { publishComment } = usePublishComment(publishCommentOptions);
await publishComment();