@supunlakmal/hooks
Version:
A collection of reusable React hooks
16 lines (15 loc) • 869 B
TypeScript
import { Reducer, Dispatch } from 'react';
/**
* A hook that wraps React's `useReducer` to provide console logging
* of actions and state changes during development.
* Logs are only output when `process.env.NODE_ENV` is 'development'.
*
* @template S - The type of the state.
* @template A - The type of the action.
* @param reducer - The reducer function `(state: S, action: A) => S`.
* @param initialState - The initial state value.
* @param initializer - Optional function to compute the initial state lazily.
* @param loggerName - Optional name to identify this reducer instance in logs.
* @returns A tuple containing the current state and the dispatch function, same as `useReducer`.
*/
export declare const useReducerLogger: <S, A>(reducer: Reducer<S, A>, initialState: S, initializer?: (initialArg: S) => S, loggerName?: string) => [S, Dispatch<A>];