# 실행 취소와 다시 실행 {#history}

Source: [React 에디터에 실행 취소와 다시 실행 추가하기 · Yurich](https://leeyujoo.com/yurich/ko/features/history/)

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

Package version: `0.1.2`

실행 취소와 다시 실행 버튼을 이력에 연결합니다.

## 직접 확인하기 {#try-it}

에디터에 내용을 입력한 뒤 **실행 취소**, **다시 실행**를 차례로 누르세요. 실행 취소는 저장된 선택 영역도 복원합니다. 단축키는 `Mod+Z`로 취소, `Mod+Shift+Z`나 `Mod+Y`로 다시 실행입니다.

## 에디터에 추가하기 {#setup}

에디터 인스턴스에서 바로 실행 이력을 사용할 수 있습니다. `useCanUndo`와 `useCanRedo`로 버튼의 활성 여부를 연결하세요.

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

export function HistoryEditor() {
  const editor = useEditor({
    extensions: [],
    initialValue: "<p>이 줄을 지워 보세요. 실행 취소가 기다리고 있습니다.</p>",
    historyLimit: 50,
  });
  const canUndo = useCanUndo(editor);
  const canRedo = useCanRedo(editor);

  return (
    <EditorProvider editor={editor}>
      <div role="group" aria-label="편집 이력">
        <button type="button" disabled={!canUndo} onClick={() => editor.history.undo()}>
          실행 취소
        </button>
        <button type="button" disabled={!canRedo} onClick={() => editor.history.redo()}>
          다시 실행
        </button>
      </div>
      <EditorContent ariaLabel="편집기" />
    </EditorProvider>
  );
}
```

## 동작 알아두기 {#behavior}

`historyLimit`의 기본값은 100입니다. 다른 문서를 열 때 이전 문서로 되돌아가면 안 된다면 `setHTML(html, { history: false })`로 이력을 초기화하세요.

[기능](https://leeyujoo.com/yurich/ko/features/)
