onEvent
Adds an event listener for Dynamic client events. Use this to react to authentication state changes, wallet updates, and other client events.Usage
Parameters
Returns
() => void - A function that can be called to remove the listener.
Examples
Track wallet account changes
This example uses React; the JavaScript SDK is framework-agnostic and can be used with any frontend or in Node.
Multiple event listeners
Common Events
You can use
initStatusChanged with status 'finished' to wait until the client is ready before calling other SDK methods. See Initializing the Dynamic Client for init statuses.
React patterns
Subscription in useEffect
Return the unsubscribe function directly fromuseEffect — no need for offEvent. Or use useOnEvent from @dynamic-labs-sdk/react-hooks to handle the subscription and cleanup automatically:
Reactive state
For SDK state that should trigger re-renders (wallet accounts, user, init status, session), use the hooks from@dynamic-labs-sdk/react-hooks — they subscribe to the relevant events internally:
Related functions
- offEvent - Unsubscribe from events