# Urungkan dan ulangi {#history}

Source: [Tambahkan Undo dan Redo ke editor React · Yurich](https://leeyujoo.com/yurich/id/features/history/)

Package: [`yurich`](https://www.npmjs.com/package/yurich)

Package version: `0.1.2`

Hubungkan tombol Undo dan Redo dengan riwayat.

## Coba sendiri {#try-it}

Ubah teks dan klik **Urungkan**, lalu **Ulangi**. Riwayat juga memulihkan pilihan.

## Tambahkan ke editor {#setup}

Riwayat sudah tersedia. Gunakan `useCanUndo` dan `useCanRedo` untuk menyinkronkan tombol.

```tsx
import { EditorContent, EditorProvider, useCanRedo, useCanUndo, useEditor } from 'yurich';

export function HistoryEditor() {
  const editor = useEditor({
    extensions: [],
    initialValue: "<p>Hapus baris ini. Kamu bisa mengurungkannya.</p>",
    historyLimit: 50,
  });
  const canUndo = useCanUndo(editor);
  const canRedo = useCanRedo(editor);

  return (
    <EditorProvider editor={editor}>
      <div role="group" aria-label="Riwayat edit">
        <button type="button" disabled={!canUndo} onClick={() => editor.history.undo()}>
          Urungkan
        </button>
        <button type="button" disabled={!canRedo} onClick={() => editor.history.redo()}>
          Ulangi
        </button>
      </div>
      <EditorContent ariaLabel="Editor" />
    </EditorProvider>
  );
}
```

## Perilaku yang perlu diperhatikan {#behavior}

Nilai bawaan `historyLimit` adalah 100. `setHTML(html, { history: false })` memulai riwayat baru.

[Fitur](https://leeyujoo.com/yurich/id/features/)
