Skip to content

Type Alias: ActionFn<C, K>

API / @xmachines/play-dom / ActionFn

type ActionFn<C, K> = (params, setState, state) => Promise<void>;

Defined in: packages/play-dom/src/json-render/types.ts:396

Catalog-typed action function — mirrors ActionFn<C, K> from @json-render/react, /solid, /vue.

  • params is typed to the exact param schema defined in the catalog, or undefined if the spec provided no params. Guard against undefined before accessing params.
  • setState writes to the @xstate/store-backed local state store. Use it to update ephemeral UI state (e.g. form field values, error messages) from within an action handler.
  • state is 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

ParameterType
paramsInferActionParams<C, K> | undefined
setStateSetState
stateStateModel

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 });
};