// Manage undo/redo state for any data structure
const [state, { undo, redo }] = useUndoRedo(initialState);
Perfect for text editors, form builders, drawing apps, or any application requiring undo/redo functionality.
Current: Initial state
import { useUndoRedo } from '@usegrand/react-hokss'; function TextEditor() { const [text, { undo, redo, canUndo, canRedo }] = useUndoRedo(''); return ( <div> <textarea value={text} onChange={(e) => setText(e.target.value)} /> <button onClick={undo} disabled={!canUndo}> Undo </button> <button onClick={redo} disabled={!canRedo}> Redo </button> </div> ); }
Initial value for the state
Configuration options (optional)
Current value and action methods
Function to undo last change
Function to redo last undone change
Boolean indicating if undo is available
Boolean indicating if redo is available