Skip to main content

useGenerateAccount

Hook to generate a new account.

Usage

import { useAccounts, useGenerateAccount } from '@kibisis/katavault-react';

function Accounts() {
const accounts = useAccounts();
const generateAccount = useGenerateAccount();
const handleOnAddAccountClick = useCallback(() => {
generateAccount('Personal', {
onError: (error) => {
console.error(error);
},
onSuccess: (result: Account) => {
console.log(`added new account ${account.address}`);
},
});
}, [generateAccount]);

return (
<div>
{accounts.map(({ address, name }) => (
<div>
<p>Address: {address}</p>
<p>Name: {name ?? '-'}</p>
</div>
))}

<button onClick={handleOnAddAccountClick}>Generate account</button>
</div>
);
}

Returns

(params?: string, options?: { onError, onSuccess }) => void

The function can be called with callbacks that are invoked on error/success.

onError

(error: BaseError, params?: string) => void | Promimse<void>

This will be invoked if there was an error.

onSuccess

(result: Account, params?: string) => void | Promimse<void>

This will be invoked if the account generation was successful.

See also