Action types
Every state change in input-actions is a tuple whose first element names what the action does. The full set divides into three families: sync state, async, and state machine. Plus event placeholders, which are values you can put inside any action that get resolved at dispatch time.
The full union is Action in @input-actions/core (source) — single source of truth. New variants are added there; everything downstream derives.
Sync state actions
Section titled “Sync state actions”These mutate state via the shared applyAction reducer. Same effect across every adapter (ADR 0015).
action/save
Section titled “action/save”['action/save', path: string[], value: any]Set the value at path. Creates intermediate objects as needed.
['action/save', ['user', 'name'], 'Ada']['action/save', ['todos', todoId, 'done'], true]['action/save', ['count'], 0] // overwrite primitives tooaction/toggle
Section titled “action/toggle”['action/toggle', path: string[]]Flip the boolean at path. Sets to true if the current value is falsy.
['action/toggle', ['ui', 'sidebarOpen']]['action/toggle', ['todos', todoId, 'done']]action/increment
Section titled “action/increment”['action/increment', path: string[], by?: number]Add by (default 1) to the number at path. Treats missing/undefined as 0.
['action/increment', ['count']]['action/increment', ['count'], 10]action/decrement
Section titled “action/decrement”['action/decrement', path: string[], by?: number]Symmetric to action/increment.
['action/decrement', ['lives']]['action/decrement', ['retries'], 1]action/push
Section titled “action/push”['action/push', path: string[], item: any]Append item to the array at path. Treats missing as [].
['action/push', ['todos'], { id: '1', text: 'Ship', done: false }]['action/push', ['log'], 'connected']action/remove
Section titled “action/remove”['action/remove', path: string[], item: any]Filter item out of the array at path by strict equality. For object arrays where you need predicate-based removal, model state as a keyed map and use action/save with undefined to drop a slot.
['action/remove', ['tags'], 'urgent']action/merge
Section titled “action/merge”['action/merge', path: string[], patch: Record<string, any>]Shallow-merge patch into the object at path. Treats missing as {}.
['action/merge', ['user', 'profile'], { bio: 'New bio', updatedAt: Date.now() }]action/reset
Section titled “action/reset”['action/reset'] // whole-state reset['action/reset', path: string[]] // slice resetRestores the slice (or the entire state) to its initialState. With a path, sibling state is preserved.
['action/reset'] // full wipe['action/reset', ['user']] // reset just user slice['action/reset', ['form', 'errors']] // reset nested sliceaction/batch
Section titled “action/batch”['action/batch', actions: Action[]]Dispatch the nested actions in order. Lets you express multi-step updates as a single composable tuple.
[ 'action/batch', [ ['action/save', ['form', 'submitted'], true], ['action/reset', ['form', 'errors']], ['action/save', ['ui', 'modalOpen'], false], ],]action/event
Section titled “action/event”['action/event', 'event/preventDefault']['action/event', 'event/stopPropagation']Imperative event-side effects you’d otherwise reach for in a callback. Lets actions(...) cover form submissions and links without dropping back to closures.
<form onSubmit={actions([ ['action/event', 'event/preventDefault'], ['action/async-prevent', 'submit', 'submitForm'],])}>Event placeholders
Section titled “Event placeholders”Strings that appear in an action’s value slot and get resolved from the React event at dispatch time. The action tuple stays pure data; the value is filled in when the handler fires.
| Placeholder | Resolves to |
|---|---|
'event/target.value' | event.target.value — text inputs, selects, textareas |
'event/target.checked' | event.target.checked — checkboxes, radio buttons |
'event/target.selectedIndex' | event.target.selectedIndex — selects |
'event/target.files' | event.target.files — file inputs |
'event/target.dataset' | event.target.dataset — custom data-* attributes |
'event/key' | event.key — keyboard event |
'event/keyCode' | event.keyCode — keyboard event (legacy) |
'event/clientX' | event.clientX — mouse event |
'event/clientY' | event.clientY — mouse event |
'event/timestamp' | event.timeStamp — milliseconds since page load |
'event/type' | event.type — 'click', 'change', … |
Used inside any action’s value slot:
<input onChange={actions(['action/save', ['user', 'name'], 'event/target.value'])}/><input type="checkbox" onChange={actions(['action/save', ['agreed'], 'event/target.checked'])}/>Callback arguments: event/arg
Section titled “Callback arguments: event/arg”Not every handler receives a DOM event. A tab bar calls onSelect('public'); a slider calls onChange(min, max). For those, read the handler’s own arguments:
| Placeholder | Resolves to |
|---|---|
'event/arg' | the handler’s first argument, as-is |
'event/arg.N' | the Nth argument (0-based): 'event/arg.1' is the second |
<Tabs onSelect={actions(['action/save', ['feedTab'], 'event/arg'])} /><RangeSlider onChange={actions([ ['action/save', ['price', 'min'], 'event/arg.0'], ['action/save', ['price', 'max'], 'event/arg.1'],])} />Handlers from actions(...) and useBoundActions accept any arguments, so they type-check against any callback prop. The first argument is still what event/target.* reads. Given a plain value instead of an event, those placeholders resolve to undefined, and event/preventDefault / event/stopPropagation do nothing.
Async actions
Section titled “Async actions”Async actions are calls to a named asyncHandler. The library tracks lifecycle metadata under state._async[opId] (ADR 0008). Handlers receive {signal: AbortSignal} as their last argument so cancellation flows through.
action/async
Section titled “action/async”['action/async', opId: string, handlerName: string, options?: AsyncConcurrencyStrategy | AsyncOptions, ...args: any[]]The general form. options can be a strategy string ('allow', 'prevent', 'cancel', 'queue', 'debounce') or an AsyncOptions object with optional strategy, onSuccess, onError, and delay. Default strategy is allow.
['action/async', 'submit', 'submitForm', { strategy: 'prevent', onSuccess: [['action/save', ['submitted'], true]] }, formData]['action/async', 'load', 'loadHistory', 'allow', channelId]['action/async', 'fetch', 'fetchUser'] // defaults to 'allow'action/async-prevent
Section titled “action/async-prevent”['action/async-prevent', opId, handlerName, ...args]Shorthand for the prevent strategy. While an op with opId is in flight, duplicate dispatches are ignored.
['action/async-prevent', 'connect', 'connect']action/async-cancel
Section titled “action/async-cancel”['action/async-cancel', opId, handlerName, ...args]Shorthand for cancel. Aborts the in-flight op via its AbortSignal and starts a new one with the same opId. Older responses can no longer overwrite newer state.
['action/async-cancel', 'search', 'searchMessages', query]action/async-queue
Section titled “action/async-queue”['action/async-queue', opId, handlerName, ...args]Shorthand for queue. Subsequent dispatches with the same opId are appended to a per-op queue and drained one at a time.
['action/async-queue', 'send-message', 'sendMessage', channelId, text]action/async-debounce
Section titled “action/async-debounce”['action/async-debounce', opId, handlerName, delayMs: number, ...args]Shorthand for debounce. Coalesces rapid dispatches; only the latest fires after delayMs of silence. If the previous call is still running when it fires, that call is aborted, so a slow earlier response can’t overwrite a newer one. The searchAsYouType(opId, handler, queryPath, delay) helper pairs this with saving the input.
['action/async-debounce', 'search', 'searchMessages', 200, query]Machine actions
Section titled “Machine actions”State-machine transitions are dispatched as tuples too. The full showcase, including FSM definition and onEnter/onExit hooks, is on the machine actions page. Quick reference here:
machine/transition
Section titled “machine/transition”['machine/transition', machineName, targetMode, ...sideEffects: Action[]]Validated transition. Falls through with a warning if not allowed.
machine/transition-if
Section titled “machine/transition-if”['machine/transition-if', machineName, targetMode, successActions: Action[], fallbackActions: Action[]]Conditional dispatch — fires successActions if the transition is allowed, fallbackActions otherwise.
machine/force
Section titled “machine/force”['machine/force', machineName, targetMode, ...sideEffects: Action[]]Bypasses the validator. Use sparingly — for recovery / debug.
machine/sequence
Section titled “machine/sequence”['machine/sequence', machineName, steps: Array<{mode: string, actions?: Action[]}>]Step the machine through multiple modes, each step optionally dispatching follow-ups. Fires onEnter/onExit per step.
machine/retry
Section titled “machine/retry”['machine/retry', machineName, targetMode, maxRetries: number, retryActions: Action[]]Try the transition up to maxRetries times, dispatching retryActions between attempts.
machine/delay
Section titled “machine/delay”['machine/delay', machineName, targetMode, delayMs: number, delayedActions: Action[]]Schedule the transition + follow-ups to fire after delayMs.
How are these dispatched?
Section titled “How are these dispatched?”The Actions as data page covers the underlying idea. The recommended call shape for event handlers is actions(input) from useActions() (or from useLocalActions’s return), where input is a single action tuple or an array of them. For programmatic dispatches (inside async handlers, in effects), reach for useDispatch() directly.
How are new action types added?
Section titled “How are new action types added?”Edit Action in packages/core/src/types.ts, then update applyAction.ts (sync actions) or the async/machine executors (async + machine actions). Every adapter inherits the new type automatically — that’s the ADR 0015 payoff. Add a test in packages/core/src/store/StoreProvider.test.tsx or useLocalActions.test.ts.