# useUndoRedo

Source: https://sdk.pdf.net/docs/v1/reference/useUndoRedo



Undo and redo commands with their availability.

```ts
const { undo, redo, canUndo, canRedo } = useUndoRedo()
```

* `canUndo` and `canRedo` re-render the component as the history changes; use them to disable the buttons.
* `undo` and `redo` throw `DocumentNotLoadedError` when no document is loaded.

## Behavior [#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](https://sdk.pdf.net/docs/v1/reference/useUndoBoundary).
* Undo and redo return the [document revision](https://sdk.pdf.net/docs/v1/reference/useDocumentRevision) 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](https://sdk.pdf.net/docs/v1/reference/useSetWidgetProps) and [useSetParagraphProps](https://sdk.pdf.net/docs/v1/reference/useSetParagraphProps)) never enter the history.

## Example [#example]

```tsx
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>
    </>
  )
}
```

