Create React-backed editors with usePliteEditor when a React component owns
the editor lifetime.
import { Plite, usePliteEditor } from "@platejs/plite-react";
const MyEditor = () => {
const editor = usePliteEditor({
initialValue: [{ type: "paragraph", children: [{ text: "" }] }],
});
return <Plite editor={editor}>...</Plite>;
};import { Plite, usePliteEditor } from "@platejs/plite-react";
const
usePliteEditor creates one editor for the component lifetime and installs
React, DOM, clipboard, and default history capabilities. The editor exposes host
APIs through editor.api.
editor.api.dom.focus();
editor.api.dom.clipboard.insertTextData(dataTransfer);
editor.api.react.isComposing();editor.api.dom.focus();
editor.api.dom.clipboard.insertTextData(dataTransfer);
editor.api.react.isComposing();Use createReactEditor when the editor is created outside a component or
inside a custom hook that owns the same one-shot lifetime.
const editor = createReactEditor({
initialValue: [{ type: "paragraph", children: [{ text: "" }] }],
});const editor = createReactEditor({
initialValue: [{ type: "paragraph", children: [{ text: "" }] }],
});Use the lower-level react({ dom }) extension only when composing extensions
through createEditor. Pass the exact DOM descriptor that React installs as a
dependency.
import { createEditor } from "@platejs/plite";
import { dom } from "@platejs/plite-dom";
import { react } from "@platejs/plite-react";
const DOMExtension = dom();
const editor = createEditor({
extensions: [react({ dom: DOMExtension })],
initialValue: [{ type: "paragraph", children: [{ text: "" }] }],
});import
Configure the internal Plite clipboard payload with clipboardFormatKey.
const editor = createReactEditor({
clipboardFormatKey: "x-acme-editor-fragment",
initialValue,
});const editor = createReactEditor({
clipboardFormatKey: "x-acme-editor-fragment",
initialValue,
});See React Editor for DOM, focus, selection, and clipboard APIs.