Skip to main content

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

Returns

void

Important Notes

  • The listener parameter 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

Use useOnEvent 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).
Last modified on June 24, 2026