ReactHooks
useWalletConnection
React hook to manage wallet connection status and information in a Sui dApp.
The useWalletConnection hook provides access to the current wallet connection status and
information.
All dApp Kit hooks must be used within components that are descendants of
DAppKitProvider. Using them outside will result in an error.
Usage
import { useWalletConnection } from '@mysten/dapp-kit-react';
export function MyComponent() {
const connection = useWalletConnection();
if (connection.status === 'disconnected') {
return <div>Please connect your wallet</div>;
}
if (connection.status === 'connecting') {
return <div>Connecting...</div>;
}
// status === 'connected'
return (
<div>
<p>Connected to: {connection.wallet.name}</p>
<p>Address: {connection.account.address}</p>
</div>
);
}Return value
{
status: 'disconnected' | 'connecting' | 'reconnecting' | 'connected';
wallet: UiWallet | null;
account: UiWalletAccount | null;
supportedIntents: string[];
isConnected: boolean;
isConnecting: boolean;
isReconnecting: boolean;
isDisconnected: boolean;
}