# 创建编辑器 {#use-editor}

Source: [创建编辑器 | Yurich React 编辑器 API 参考 · Yurich](https://leeyujoo.com/yurich/zh-cn/api/use-editor/)

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

Package version: `0.1.2`

```ts
declare function useEditor(options: EditorOptions): EditorInstance;

type EditorOptions = {
  extensions: Extension[];
  initialValue?: string;
  onChange?: (html: string) => void;
  onChangeJSON?: (json: DocumentJSON) => void;
  sanitize?: boolean;
  historyLimit?: number;
};
```

`extensions` 必填。`initialValue` 是只读取一次的初始 HTML。`historyLimit` 默认为 100。`sanitize` 默认为 `true`，控制输出 HTML 的清理。

`onChange` 提供 HTML，`onChangeJSON` 提供 JSON。每帧最多通知一次。用 `{ history: false }` 加载时，相同的 HTML 也可能触发回调。
