postMessage.
Subscribing to Events
Use theuseWidgetLightEvents() hook to get the event emitter, then subscribe with on and unsubscribe with off:
Key Details
-
Module-level singleton — the event bus is a module-level singleton, so
useWidgetLightEvents()can be called from any component. It does not need to be co-located with<LiFiWidgetLight>and does not require any provider wrapping. -
Subscription-tracked forwarding — events are only forwarded from the iframe when at least one host-side listener is subscribed. When you call
events.on(eventName, handler), the host sends aWIDGET_EVENT_SUBSCRIBEmessage to the iframe. When the last listener for an event is removed, the host sendsWIDGET_EVENT_UNSUBSCRIBE. This avoids unnecessarypostMessagetraffic. -
Stable reference — the emitter returned by
useWidgetLightEvents()is a stable module-level object. You do not need to memoize it or add it to dependency arrays (though it is safe to do so).
Tracking Route Execution
A common use case is tracking the lifecycle of a swap or bridge route:Event Reference
Route Execution Events
Form and Selection Events
Wallet Events
UI Events
Settings and Preferences Events
Payload Types
All payload types are exported from@lifi/widget-light:
Route-carrying payloads (
WidgetLightRouteExecutionUpdate, WidgetLightRouteSelected) use unknown for the route field because the full route type from @lifi/sdk is not available in Widget Light’s zero-dependency type system. Cast to your local @lifi/sdk types if you need typed access to route properties.WidgetLightEvent Enum
All event names are available as theWidgetLightEvent enum:

