Skip to content

@statesync/redux


@statesync/redux / withSnapshotHandling

Function: withSnapshotHandling()

ts
function withSnapshotHandling<State, Action>(reducer): (state, action) => State;

Defined in: redux.ts:284

Higher-order function that wraps an existing reducer to automatically handle SNAPSHOT_ACTION_TYPE actions.

When the wrapped reducer receives a snapshot action:

  • In 'patch' mode: returns { ...state, ...payload } (shallow merge).
  • In 'replace' mode: returns payload as State (full replacement).

All other actions are forwarded to the original reducer unchanged.

Type Parameters

Type ParameterDescription
State extends Record<string, unknown>The shape of the reducer's state.
ActionThe union of actions the original reducer handles.

Parameters

ParameterTypeDescription
reducer(state, action) => StateThe original reducer to wrap.

Returns

A new reducer that intercepts snapshot actions.

ts
(state, action): State;

Parameters

ParameterType
stateState | undefined
action| Action | SnapshotAppliedAction<State>

Returns

State

Example

ts
import { configureStore } from '@reduxjs/toolkit';
import { withSnapshotHandling } from '@statesync/redux';

const store = configureStore({
  reducer: withSnapshotHandling(rootReducer),
});

Released under the MIT License.