Wallet UI LogoWallet UI

useWalletUiAccount

A hook to access the current wallet account and its setter.

The useWalletUiAccount hook provides direct access to the currently selected wallet account and the React dispatcher to update it.

For most common use cases, consider using the main useWalletUi hook. It offers a simpler API with connect() and disconnect() functions instead of a raw state dispatcher.

Return Value

The hook returns an object with the following properties:

NameTypeDescription
accountUiWalletAccountThe currently selected wallet account.
walletUiWalletThe wallet that the current account belongs to.
clusterSolanaClusterThe currently selected Solana cluster.
setAccountReact.Dispatch<React.SetStateAction<UiWalletAccount>>The React dispatcher to update the selected account.

Example

This example shows how you could manually clear the selected wallet.

import { useWalletUiAccount } from '@wallet-ui/react';

function AccountDetails() {
    const { account, setAccount } = useWalletUiAccount();

    if (!account) {
        return <p>No account selected.</p>;
    }

    return (
        <div>
            <p>Account: {account.address}</p>
            <button onClick={() => setAccount(undefined)}>Clear Account</button>
        </div>
    );
}