useSwitchAccount
The useSwitchAccount
hook is a mutation hook for establishing a connection to a specific wallet.
Live Editor
function UseSwitchAccountExample() { const { mutate: switchAccount } = useSwitchAccount(); const accounts = useAccounts(); return ( <div style={{ padding: 20 }}> <ul> {accounts.map((account) => ( <li key={account.address}> <button onClick={() => { switchAccount( { account }, { onSuccess: () => console.log(`switched to ${account.address}`), }, ); }} > Switch to {account.address} </button> </li> ))} </ul> </div> ); }
Result
Loading...
Arguments
-
args
- Arguments passed to theconnect
function of the wallet.account
- The account to switch to.
-
options
- Options passed theuseMutation
hook from @tanstack/react-query.