applyAction
applyAction<
TState>(state,action,initialState):TState
Defined in: store/applyAction.ts:30
Apply a sync action to a state object and return the next state.
Pure function: no side effects, no logging, no adapter knowledge. Adapters
call this from their dispatch to compute the next state, then commit via
their underlying mechanism (assigning this.state, returning from a slice
reducer, calling set() on a Zustand store, writing to a Jotai atom, …).
Returns state unchanged for:
- async actions (
action/async*): handled upstream byasyncExecutor. - machine actions (
machine/*): handled upstream byexecuteActions. action/event: an event-manipulation directive, not a state change.- unknown action types.
Also returns state unchanged for writes that change nothing: saving the
value already at a path, merging keys that already match, removing an item
that isn’t there, deleting an absent key (and batches made only of those).
Reference-stability: when this returns a new state, the top-level reference
differs from state. Callers that compare references (useSyncExternalStore,
adapter notify loops) get correct change detection.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TState |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
state | TState |
action | Action |
initialState | TState |
Returns
Section titled “Returns”TState