BoardKitFrontend
useHistory
Undo and redo operations
useHistory provides undo/redo functionality backed by the History class from @hfu.digital/boardkit-core.
Signature
function useHistory(): UseHistoryResult;Return Type
interface UseHistoryResult {
undo: () => void;
redo: () => void;
canUndo: boolean;
canRedo: boolean;
}| Property | Description |
|---|---|
undo | Undo the last operation |
redo | Redo the last undone operation |
canUndo | true if there are operations to undo |
canRedo | true if there are operations to redo |
Usage
import { useHistory } from '@hfu.digital/boardkit-react';
function UndoRedoButtons() {
const { undo, redo, canUndo, canRedo } = useHistory();
return (
<div>
<button onClick={undo} disabled={!canUndo}>Undo</button>
<button onClick={redo} disabled={!canRedo}>Redo</button>
</div>
);
}Keyboard Shortcuts
When useKeyboardShortcuts is active, undo/redo is also available via:
| Shortcut | Action |
|---|---|
Ctrl+Z | Undo |
Ctrl+Y or Ctrl+Shift+Z | Redo |
History Depth
The history stack has a maximum depth of 100 operations by default. When the limit is reached, the oldest operations are evicted.