Function: useOnEvents()
Subscribes the component to events on the active container's EventBus.
Remarks
Pass a single event type, an array of types, or only a handler to receive every event, mirroring EventBus.subscribe. The subscription is scoped to the component and is removed automatically when it unmounts, the active container changes, or the set of listened types changes. Requires EventBus to be bound in the active container or an ancestor.
Param
typesOrHandler
The event type, an array of event types, or the handler itself to receive every event.
Param
maybeHandler
The handler invoked for matching events. Omit it when the first argument is the handler.
Throws
WirestateError if the active container cannot resolve EventBus.
Example
// Listen to one event type.
useOnEvents("CART_ITEM_ADDED", (event) => console.info(event.payload));
// Listen to several event types.
useOnEvents(["CART_ITEM_ADDED", "CART_VIEWED"], (event) => console.info(event.type));
// Listen to every event.
useOnEvents((event) => console.info(event.type));Call Signature
function useOnEvents(handler: EventHandler): void;Defined in: src/wirestate-react/events/use-on-events.ts:16
Subscribes the component to every event on the active EventBus.
Parameters
| Parameter | Type | Description |
|---|---|---|
handler | EventHandler | Handler invoked for every event. |
Returns
void
Call Signature
function useOnEvents(type: EventType, handler: EventHandler): void;Defined in: src/wirestate-react/events/use-on-events.ts:24
Subscribes the component to one event type on the active EventBus.
Parameters
| Parameter | Type | Description |
|---|---|---|
type | EventType | Event type to listen for. |
handler | EventHandler | Handler invoked for matching events. |
Returns
void
Call Signature
function useOnEvents(types: readonly EventType[], handler: EventHandler): void;Defined in: src/wirestate-react/events/use-on-events.ts:32
Subscribes the component to several event types on the active EventBus.
Parameters
| Parameter | Type | Description |
|---|---|---|
types | readonly EventType[] | Event types to listen for. |
handler | EventHandler | Handler invoked for matching events. |
Returns
void