Summary

An alternative to using event callbacks or 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

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);
});

You can see the available public events here