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.
offEvent
Removes an event listener from Dynamic client events. This function unsubscribes a previously registered event listener from the specified Dynamic client event.Usage
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | The event name to remove the listener from. |
listener | Function | The callback function to remove. |
client | DynamicClient (optional) | The Dynamic client instance. Only required when using multiple clients. |
Returns
void
Important Notes
- The
listenerparameter must be the exact same function reference that was used when adding the listener - Anonymous functions cannot be removed with
offEvent- store a reference to the function first
Examples
Basic event cleanup
Using returned cleanup function from onEvent
React
UseuseEvent from @dynamic-labs-sdk/react-hooks to subscribe in components — it handles cleanup for you. See onEvent — React patterns for examples.
You can also return the unsubscribe function from onEvent as the useEffect cleanup (no offEvent needed for that case). Use offEvent when you must remove a listener by reference outside a useEffect (for example, a class component or imperative code).
Related functions
- onEvent - Subscribe to events