useEvent
Stable · since 0.1.0
Returns a stable callback that fires a typed event on a trigger. Identity is preserved across renders, so passing it to useEffect dependency lists is safe.
Import
Section titled “Import”Signature
Section titled “Signature”The return type is inferred from the trigger’s schema. Void-payload events return a () => void emitter; otherwise the emitter takes the typed payload.
Parameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
trigger | Trigger<S> | The trigger returned by createTrigger. |
eventName | K extends EventKey<S> | Must be one of the keys listed in trigger’s events schema and events: [...] array. |
Returns
Section titled “Returns”A stable emitter function:
voidpayload →() => void- Typed payload →
(payload: …) => void
The function is wrapped in useCallback, so its identity stays the same as long as runtime and eventName don’t change.
Examples
Section titled “Examples”Plain payload
Section titled “Plain payload”Void payload
Section titled “Void payload”Passing into another effect
Section titled “Passing into another effect”Related
Section titled “Related” useCondition Register a pull-only condition getter.
useAction Register an action handler.
Events guide Narrative walkthrough — scheduling, batching, broadcast.
createNamedHooks `useNewMessageEvent` shorthand.