# Status

Check the current connection status on loading your app.

```ts title="Pure JS"
import { mega } from '@megaeth-labs/wallet-sdk';

const { status, address, network } = await mega.status();
```

```tsx title="React"
import { useStatus } from '@megaeth-labs/wallet-sdk-react';

export default function Component() {
    const { initialised, status, address, network, error } = useStatus();

    if (error) return <p>Couldn't load the wallet: {error.message}</p>;
    if (!initialised) return <p>Loading…</p>;

    return (
        <ul>
            <li>Status: {status}</li>
            <li>Network: {network}</li>
            {address && <li>Address: {address}</li>}
        </ul>
    );
}
```

```tsx title="Wagmi"
import { useAccount } from 'wagmi';

export default function Component() {
    const { status, address, chain } = useAccount();

    if (status === 'connecting' || status === 'reconnecting') return <p>Loading…</p>;

    return (
        <ul>
            <li>Status: {status}</li>
            <li>Network: {chain?.name}</li>
            {address && <li>Address: {address}</li>}
        </ul>
    );
}
```

## Status Changes
Get notified when a user switches account, changes network or disconnects.

```ts title="Pure JS"
import { mega } from '@megaeth-labs/wallet-sdk';

mega.events.onStatusChange(({ status, address }) => {
    console.log('Wallet is now', status, address);
});
```

```tsx title="React"
import { useStatus } from '@megaeth-labs/wallet-sdk-react';

// useStatus re-renders whenever the connection changes.
export default function WalletBadge() {
    const { status, address } = useStatus();

    return <span>{status === 'connected' ? address : 'Not connected'}</span>;
}
```

```tsx title="Wagmi"
import { useAccount } from 'wagmi';

// useAccount re-renders whenever the connection changes.
export default function WalletBadge() {
    const { address, isConnected } = useAccount();

    return <span>{isConnected ? address : 'Not connected'}</span>;
}
```

```ts
export interface ConnectionStatus {
    status: 'connected' | 'disconnected' | 'cancelled';
    address?: `0x${string}`;
    network: 'mainnet' | 'testnet';
}
```
