werkbank
    Preparing search index...

    Function createReducerHook

    • Creates a custom hook for managing state with reducers (similar to Redux Toolkit).

      Type Parameters

      • S

        The state type.

      • R extends ReducerMap<S>

        The reducer map type.

      Parameters

      • config: ReducerConfig<S, R>

        The reducer configuration (initialState, reducers).

      Returns (init?: (i: S) => S) => readonly [S, Actions<R>]

      A custom hook.

      Uses Immer for immutable state updates. Returns a hook that provides the state and action dispatchers.

      const useCounter = createReducerHook({
      initialState: { count: 0 },
      reducers: {
      increment: (state) => { state.count += 1; }
      }
      });

      const [state, { increment }] = useCounter();