My App
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;
}
PropertyDescription
undoUndo the last operation
redoRedo the last undone operation
canUndotrue if there are operations to undo
canRedotrue 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:

ShortcutAction
Ctrl+ZUndo
Ctrl+Y or Ctrl+Shift+ZRedo

History Depth

The history stack has a maximum depth of 100 operations by default. When the limit is reached, the oldest operations are evicted.

On this page