/** * An (abstract) hook that wraps React’s useReducer hook and handles storing and loading reducer state * using provided functions. */ import type { Reducer, Dispatch } from 'react'; declare const LOAD_STATE_ACTION_TYPE: "loadedState"; export interface BaseAction { type: string; payload?: any; } /** Action issued when previously stored state is loaded. */ export interface LoadStateAction extends BaseAction { type: typeof LOAD_STATE_ACTION_TYPE; /** Loaded state. */ payload: S; } export declare type StateReducerHook = (reducer: Reducer, initialState: S, initializer: ((initialState: S) => S) | null) => [state: S, dispatch: Dispatch]; export declare type PersistentStateReducerHook = ( /** Each component should specify a unique storage key. */ storageKey: string, /** * Calls to store state will be debounced according to this delay * in case state change too often. */ storageDebounceMS?: number, validateLoadedState?: (loadedValue: Partial & any) => loadedValue is S, ...args: Parameters>) => [state: S, dispatch: Dispatch, stateRecalled: boolean]; /** * A reducer that persists each new state, * and attempts to load persisted state when component is mounted. * * During the initial load, `initialized` is set to false. * * `storeState` is called on each change of state but debounced. * * NOTE: that state S cannot be an empty object, * in such a case `initialState` will always be used. */ declare function usePersistentStateReducer(storeState: (key: string, newState: S) => void, loadState: (key: string) => Promise, ...args: Parameters>): [state: S, dispatch: Dispatch, initialized: boolean]; export default usePersistentStateReducer; export declare const initialHook: PersistentStateReducerHook;