useUndoRedo
Undo and redo commands with their availability.
const { undo, redo, canUndo, canRedo } = useUndoRedo()canUndoandcanRedore-render the component as the history changes; use them to disable the buttons.undoandredothrowDocumentNotLoadedErrorwhen no document is loaded.
Behavior
- The history tracks the local user's edits: undo reverts your changes.
- Edits made within 500 ms of each other merge into a single undo step. To keep an operation in its own step, use useUndoBoundary.
- Undo and redo return the document revision to its earlier value, so an "unsaved changes" indicator clears when all edits since the last save are undone.
- Changes applied with
excludeFromHistory(see useSetWidgetProps and useSetParagraphProps) never enter the history.
Example
import { useUndoRedo } from '@sdk-pdf/react'
function UndoRedoButtons() {
const { undo, redo, canUndo, canRedo } = useUndoRedo()
return (
<>
<button disabled={!canUndo} onClick={undo}>
Undo
</button>
<button disabled={!canRedo} onClick={redo}>
Redo
</button>
</>
)
}