# @lexical/history

> This package contains selection history helpers for Lexical.

Latest version **0.51.0** (published 2026-09-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @lexical/history
pnpm add @lexical/history
yarn add @lexical/history
bun add @lexical/history
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; popular repo.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.51.0 |
| Published | 2026-09-17 |
| First published | 2022-04-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 69.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 23875 |
| Maintainers | fantactuka, zurfyx, acywatson, ipavlov001, trueadm, etrepum |
| Keywords | lexical, editor, rich-text, history |

## Links

- npm: https://www.npmjs.com/package/@lexical/history
- Repository: https://github.com/facebook/lexical
- npm.io page: https://npm.io/package/@lexical/history

## Dependencies (3)

- [lexical](https://npm.io/package/lexical.md) 0.51.0
- [@lexical/utils](https://npm.io/package/@lexical/utils.md) 0.51.0
- [@lexical/extension](https://npm.io/package/@lexical/extension.md) 0.51.0

## Alternatives

- [ext-list](https://npm.io/package/ext-list.md) — 6.3M weekly downloads
- [@lexical/selection](https://npm.io/package/@lexical/selection.md) — 3.8M weekly downloads
- [@lexical/text](https://npm.io/package/@lexical/text.md) — 3.6M weekly downloads
- [@lexical/clipboard](https://npm.io/package/@lexical/clipboard.md) — 3.0M weekly downloads
- [@tiptap/extension-mention](https://npm.io/package/@tiptap/extension-mention.md) — 3.0M weekly downloads

## Recent versions

- 0.51.0 (latest) — 2026-09-17
- 0.51.1-nightly.20260923.0 (nightly) — 2026-09-23
- 0.45.1-dev.0 (dev) — 2026-05-30
- 0.6.1-next.0 (next) — 2022-11-04
- 0.51.1-nightly.20260922.0 — 2026-09-22
- 0.51.1-nightly.20260921.0 — 2026-09-21
- 0.51.1-nightly.20260918.0 — 2026-09-18
- 0.50.1-nightly.20260917.0 — 2026-09-17
- 0.50.1-nightly.20260916.0 — 2026-09-16
- 0.50.1-nightly.20260915.0 — 2026-09-15
- 0.50.1-nightly.20260914.0 — 2026-09-14
- 0.50.1-nightly.20260911.0 — 2026-09-11
- 0.50.1-nightly.20260910.0 — 2026-09-10
- 0.50.1-nightly.20260909.0 — 2026-09-09
- 0.50.1-nightly.20260908.0 — 2026-09-08
- … 672 more at https://npm.io/package/@lexical/history/versions

## README

# `@lexical/history`

[![See API Documentation](https://lexical.dev/img/see-api-documentation.svg)](https://lexical.dev/docs/api/modules/lexical_history)

This package contains history helpers for Lexical.

### Methods

#### `registerHistory`

Registers necessary listeners to manage undo/redo history stack and related editor commands. It returns `unregister` callback that cleans up all listeners and should be called on editor unmount.

```js
function registerHistory(
  editor: LexicalEditor,
  externalHistoryState: HistoryState,
  delay: number,
): () => void
```

### Commands

History package handles `UNDO_COMMAND`, `REDO_COMMAND` and `CLEAR_HISTORY_COMMAND` commands. These commands could be used to work with history state:

```jsx
import {UNDO_COMMAND, REDO_COMMAND} from 'lexical';

<Toolbar>
  <Button onClick={() => editor.dispatchCommand(UNDO_COMMAND, undefined)}>Undo</Button>
  <Button onClick={() => editor.dispatchCommand(REDO_COMMAND, undefined)}>Redo</Button>
</Toolbar>;
```

### Undo/redo availability

`CAN_UNDO_COMMAND` and `CAN_REDO_COMMAND` are **deprecated**. A command only reports a change, so a listener registered after the editor is initialized never sees the current value, and there is no way to read it.

Use the `canUndo` and `canRedo` signals from `HistoryExtension` instead. They are derived from the history stacks and always hold the current value:

In React, use the `useExtensionSignalValue` hook:

```jsx
import {HistoryExtension} from '@lexical/history';
import {useExtensionSignalValue} from '@lexical/react/useExtensionSignalValue';

function UndoButton() {
  const canUndo = useExtensionSignalValue(HistoryExtension, 'canUndo');
  return <Button disabled={!canUndo}>Undo</Button>;
}
```

Outside React, read the signal directly:

```js
import {getExtensionDependencyFromEditor} from '@lexical/extension';
import {HistoryExtension} from '@lexical/history';

const {output} = getExtensionDependencyFromEditor(editor, HistoryExtension);
output.canUndo.peek();
```

---
_Source: https://npm.io/package/@lexical/history · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
