> ## 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.

# Dynamic Events

> [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.

### Summary

An alternative to using [event callbacks](https://docs.dynamic.xyz/docs/react/reference/events/events-introduction.md#event-callbacks) or [`useDynamicEvents`](https://docs.dynamic.xyz/docs/react/reference/hooks/usedynamicevents) react hook is to use `dynamicEvents` emitter directly.

It can used anywhere, even outside of a React component.

If you want to listen to events in a React component, you might want to use the `useDynamicEvents` hook instead, as it will automatically unsubscribe when the component is unmounted.

### Usage

```TypeScript theme={"system"}
import { dynamicEvents } from "@dynamic-labs/sdk-react-core";

dynamicEvents.on("primaryWalletChanged", (newPrimaryWallet) => {
  console.log('primaryWalletChanged was called', newPrimaryWallet);
});

dynamicEvents.on("primaryWalletNetworkChanged", (newNetwork) => {
  console.log('primaryWalletNetworkChanged was called', newNetwork);
});

dynamicEvents.on("userWalletsChanged", (params) => {
  console.log('userWalletsChanged was called', params);
});

dynamicEvents.on("walletConnectionQrCodeReady", (qrCodeUri) => {
  console.log('walletConnectionQrCodeReady was called', qrCodeUri);
});
```

> [!NOTE]
>
> You can see the available public events
> [here](https://docs.dynamic.xyz/docs/react/reference/hooks/usedynamicevents.md)


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