UNPKG

@supunlakmal/hooks

Version:

A collection of reusable React hooks

19 lines (18 loc) 797 B
/** * @name useResetState * @description - Hook that manages state and provides a function to reset it to its initial value. * * @template S The type of the state. * @param {S | (() => S)} initialState The initial state value or a function that returns it. * @returns {[S, React.Dispatch<React.SetStateAction<S>>, () => void]} A tuple containing the current state, the standard state setter function, and a function to reset the state to its initial value. * * @example * const [name, setName, resetName] = useResetState('Initial Name'); * * setName('Updated Name'); * // name is now 'Updated Name' * * resetName(); * // name is now 'Initial Name' */ export declare const useResetState: <S>(initialState: S | (() => S)) => [S, React.Dispatch<React.SetStateAction<S>>, () => void];