UNPKG

rooks

Version:

Essential React custom hooks ⚓ to super charge your components!

46 lines 1.42 kB
/** * useUndoRedoState * @description Setstate but can also undo and redo * @see {@link https://rooks.vercel.app/docs/useUndoRedoState} */ import { SetStateAction, Dispatch } from "react"; type UndoRedoControls = { undo: () => void; redo: () => void; /** * @deprecated * Use `isUndoPossible` instead */ canUndo: () => boolean; /** * @deprecated * Use `isRedoPossible` instead * */ canRedo: () => boolean; clearUndoStack: () => void; clearRedoStack: () => void; clearAll: () => void; isUndoPossible: boolean; isRedoPossible: boolean; }; /** * useUndoRedoState hook * * This hook manages the state with undo and redo capabilities. * * @param initialState - The initial state value * @param options - An optional object with a `maxDepth` property to limit the history and future arrays * @returns A tuple with the current state, a function to update the state, and an object with undo and redo controls * * @example * const [state, setState, controls] = useUndoRedoState(0, { maxDepth: 3 }); * // state is 0 * setState(1); // state is 1 * controls.undo(); // state is 0 * controls.redo(); // state is 1 */ declare function useUndoRedoState<T>(initialState: T, options?: { maxDepth?: number; }): [T, Dispatch<SetStateAction<T>>, UndoRedoControls]; export { useUndoRedoState }; //# sourceMappingURL=useUndoRedoState.d.ts.map