Type Alias: ActionFn<C, K>
API / @xmachines/play-dom / ActionFn
type ActionFn<C, K> = (params, setState, state) => Promise<void>;Defined in: @xmachines/json-render-dom
Catalog-typed action function — mirrors ActionFn<C, K> from @xmachines/json-render-react, /solid, /vue.
paramsis typed to the exact param schema defined in the catalog, orundefinedif the spec provided no params. Guard against undefined before accessing params.setStatewrites to the backing local state store. Use it to update ephemeral UI state (e.g. form field values, error messages) from within an action handler.stateis a snapshot of the current state model at the time the action was invoked.
Type Parameters
| Type Parameter |
|---|
C extends Catalog |
K extends keyof InferCatalogActions<C> |
Parameters
| Parameter | Type |
|---|---|
params | InferActionParams<C, K> | undefined |
setState | SetState |
state | StateModel |
Returns
Promise<void>
Example
login: async (params, setState, state) => { if (!params) return; setState((prev) => ({ ...prev, loading: true })); await actor.send({ type: "auth.login", username: params.username });};