> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Track Wallet Events/Changes

> Listen for wallet lifecycle events to keep your UI in sync.

> [card] Recommended: JavaScript SDK with React Hooks
>
> For new React apps, we recommend the JavaScript SDK with React Hooks (`@dynamic-labs-sdk/react-hooks`) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the [React quickstart (JavaScript SDK)](https://docs.dynamic.xyz/docs/javascript/reference/react-quickstart.md) to get started.

Use [`useDynamicEvents`](https://docs.dynamic.xyz/docs/react/reference/hooks/usedynamicevents) to subscribe to wallet lifecycle events from the provider and keep UI state in sync.

```tsx React theme={"system"}
import { useDynamicEvents } from '@dynamic-labs/sdk-react-core';

export function WalletEventListener() {
  // Fires when primary wallet changes (including account/network changes)
  useDynamicEvents('primaryWalletChanged', (wallet) => {
    console.log('Primary wallet changed', wallet);
  });

  // Fires when the primary wallet network changes
  useDynamicEvents('primaryWalletNetworkChanged', (networkId) => {
    console.log('Primary wallet network changed', networkId);
  });

  // Fires whenever user wallets list changes (add/remove/primary change/network change)
  useDynamicEvents('userWalletsChanged', (params) => {
    console.log('User wallets changed', params);
  });

  return null;
}
```

Tip: keep the listener component mounted at app shell level so events are captured globally; clean-up is automatic when the component unmounts.

> [!NOTE]
>
> Using the JavaScript SDK? See [Wallet Provider Events](https://docs.dynamic.xyz/docs/javascript/reference/wallets/wallet-provider-events.md) for the equivalent guide.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.