useAction
Registers an action handler — the function the runtime invokes when a trigger handler calls actions.<name>(payload). Handlers can be sync or async; their return value is awaited inside the trigger handler’s run.
Import
Section titled “Import”Signature
Section titled “Signature”The handler’s payload parameter is typed from the action schema. Void-payload actions register a () => void | Promise<void> handler.
Parameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
trigger | Trigger<S> | The trigger returned by createTrigger. |
name | K extends ActionKey<S> | An action declared in the trigger’s schema. |
handler | Function | Sync or async handler. May return void or Promise<void>. |
Returns
Section titled “Returns”void. The handler is held in a ref and the registration is set up in useEffect / cleaned up on unmount.
Examples
Section titled “Examples”Sync handler
Section titled “Sync handler”Async handler with AbortSignal
Section titled “Async handler with AbortSignal”The runtime drives the trigger handler — and therefore your async action — under the trigger’s concurrency strategy. For take-latest the AbortSignal in your trigger handler’s ctx is the one to pass downstream; if your action also wants its own abort, plumb a controller in.
Multiple reactors
Section titled “Multiple reactors”If you mount two components both calling useAction(trigger, 'showToast', …), the most recently mounted wins, and a DEV warn-once is logged. On unmount the previous handler is restored. See Ownership.