Hooks

useUndoRedo

Publisher

cermuel

50 hooks published

More from this publisher

useUndoRedo

Maintain state history and navigation.

useUndoRedo.tsx
import { useUndoRedo } from "@cermuel/hooks/react";export function useUndoRedoExample() {  const history = useUndoRedo('draft');  return <button type="button" onClick={history.undo}>Undo</button>;}

Props

Param
Type
Default Value
initialValue
T
limit?
number
100

Returns

{ value: T; set: (next: T) => void; history: T[]; index: number; canUndo: boolean; canRedo: boolean; undo: () => void; redo: () => void; reset: (next?: T) => void; }