From zbeyens. The source code is available on GitHub.

Plate
PlatePliteEditorsTemplates
GitHub16kGitHub
DiscordDiscord
  • From Plite to Plate

From Plite to Plate

PreviousNext

Move a Plite React editor to Plate's editor, plugin, and rendering model.

Plate keeps Plite's document model and moves editor setup, rendering, events, and command wiring into plugins. Migrate the editor shell first, then move custom rendering and behavior into plugins.

Install

pnpm add platejs
pnpm add platejs

Use feature packages only for the nodes, marks, or behavior you add to the editor. Plate UI users should start with Plate UI instead of rebuilding every component by hand.

Migration Map

Plite surface
Toggle DemoOverview

On This Page

InstallMigration MapEditor ShellCustom ElementsCustom BehaviorEvents And ShortcutsAPI CallsHeadless CodeRelated
Build your editor
Production-ready AI template and reusable components.
Get all-access
Plate surface
createEditor() plus withReact()usePlateEditor({ ... }) in React components, or createPlateEditor({ ... }) in factories and tests.
<Plite> plus <Editable><Plate> plus <PlateContent>.
renderElement / renderLeaf switch statementsPlugin components through .configure({ component }).
withX(editor) plugin functionsConstructor api, read, selectors, update, native Plite fields, and codec declarations built by defineCodecs.
Top-level event handlers on EditablePlugin on or shortcuts.
Transforms.* importseditor.update((tx) => tx.*).
Editor.* importseditor.read((state) => state.*), or a plugin-owned editor.api.* service.

Editor Shell

Move the editor value into the editor creation call and render the editable with PlateContent.

components/editor.tsx
'use client';
 
import { Plate, PlateContent, usePlateEditor } from 'platejs/react';
 
const initialValue = [
  {
    children: [{ text: 'Hello Plate.' }],
    type: 'paragraph',
  },
];
 
export function Editor() {
  const editor = usePlateEditor({
    initialValue,
  });
 
  return (
    <Plate editor={editor}>
      <PlateContent className="p-4" />
    </Plate>
  );
}
components/editor.tsx
'use client';
 
import { Plate, PlateContent, usePlateEditor } from 'platejs/react';
 
const initialValue = [
  {
    children: [{ text: 'Hello Plate.' }],
    type: 'paragraph',
  },
];
 
export function Editor() {
  const editor = usePlateEditor({
    initialValue,
  });
 
  return (
    <Plate editor={editor}>
      <PlateContent className="p-4" />
    </Plate>
  );

Use createPlateEditor({ ... }) when the editor is created outside React memoization.

lib/create-editor.ts
import { createPlateEditor } from 'platejs/react';
 
export const editor = createPlateEditor({
  initialValue: [
    {
      children: [{ text: 'Draft' }],
      type: 'paragraph',
    },
  ],
});
lib/create-editor.ts
import { createPlateEditor } from 'platejs/react';
 
export const editor = createPlateEditor({
  initialValue: [
    {
      children: [{ text: 'Draft' }],
      type: 'paragraph',
    },
  ],
});

Custom Elements

Replace renderElement branches with node plugins. Use .configure({ component }) when the only change is the React component.

components/editor/paragraph-plugin.tsx
import {
  ParagraphPlugin,
  PlateElement,
  type PlateElementProps,
} from 'platejs/react';
 
export function ParagraphElement({
  children,
  ...props
}: PlateElementProps<typeof ParagraphPlugin>) {
  return (
    <PlateElement className="m-0 px-0 py-1" {...props}>
      {children}
    </PlateElement>
  );
}
 
export const AppParagraphPlugin = ParagraphPlugin.configure({ component: ParagraphElement });
components/editor/paragraph-plugin.tsx
import {
  ParagraphPlugin,
  PlateElement,
  type PlateElementProps,
} from 'platejs/react';
 
export function ParagraphElement({
  children,
  ...props
}: PlateElementProps<typeof ParagraphPlugin>) {
  return (
    <PlateElement className="m-0 px-0 py-1" {...props}>
      {children}
    </PlateElement>
  );
}
 
export const AppParagraphPlugin = ParagraphPlugin.configure({ component: ParagraphElement });

If an existing document uses a different persisted type, remap that element in the closed editor schema. Plugin configuration cannot rewrite schema identity.

components/editor/document-editor.tsx
import { schema } from 'platejs';
import { createPlateEditor } from 'platejs/react';
 
const editor = createPlateEditor({
  plugins: [AppParagraphPlugin],
  schema: {
    overrides: [
      schema.override(AppParagraphPlugin, {
        element: { type: 'p' },
      }),
    ],
  },
});
components/editor/document-editor.tsx
import { schema } from 'platejs';
import { createPlateEditor } from 'platejs/react';
 
const editor = createPlateEditor({
  plugins: [AppParagraphPlugin],
  schema: {
    overrides: [
      schema.override(AppParagraphPlugin, {
        element: { type: 'p' },
      }),
    ],
  },
});

Custom Behavior

Put a reusable document command under the plugin's update contribution. The command is available inside editor.update(...) under the plugin name.

components/editor/limit-exclamation-plugin.tsx
import { definePlatePlugin } from 'platejs/react';
 
export const SignaturePlugin = definePlatePlugin('signature', {
  update: ({ tx }) => ({
    insert() {
      tx.text.insert(' - Plate');
    },
  }),
});
components/editor/limit-exclamation-plugin.tsx
import { definePlatePlugin } from 'platejs/react';
 
export const SignaturePlugin = definePlatePlugin('signature', {
  update: ({ tx }) => ({
    insert() {
      tx.text.insert(' - Plate');
    },
  }),
});

Call it from a shortcut, toolbar, menu item, or test:

commands.ts
editor.update((tx) => {
  tx.signature.insert();
});
commands.ts
editor.update((tx) => {
  tx.signature.insert();
});

Element plugins already receive schema-inferred insert, set, and remove updates. Do not wrap those generic operations in a feature method.

components/editor/callout-plugin.tsx
import { schema } from 'platejs';
import { definePlatePlugin } from 'platejs/react';
 
export const CalloutPlugin = definePlatePlugin('callout', {
  schema: {
    element: schema.element.textBlock(),
  },
});
components/editor/callout-plugin.tsx
import { schema } from 'platejs';
import { definePlatePlugin } from 'platejs/react';
 
export const CalloutPlugin = definePlatePlugin('callout', {
  schema: {
    element: schema.element.textBlock(),
  },
});
commands.ts
editor.plugin(CalloutPlugin).update.insert();
commands.ts
editor.plugin(CalloutPlugin).update.insert();

Add a custom update only when it performs behavior beyond those generic node operations. Keep that method flat and task-shaped; the portal already owns the plugin noun.

Use api for plugin-scoped immutable services, read for snapshot-local queries, and the root native Plite fields for commands, corrections, read middleware, lifecycle, activation, validation, and other substrate behavior. Combine independent fields in the constructor. Use .extend() only for an imported/prebuilt declaration, a shared factory the constructor cannot access, or an earlier-stage type dependency.

Events And Shortcuts

Move editor events into the plugin that owns the behavior.

components/editor/tab-plugin.tsx
import { definePlatePlugin } from 'platejs/react';
 
export const TabPlugin = definePlatePlugin('tab', {
  on: {
    keyDown: ({ event }) => {
      if (event.key !== 'Tab') return false;
 
      event.preventDefault();
 
      return true;
    },
  },
});
components/editor/tab-plugin.tsx
import { definePlatePlugin } from 'platejs/react';
 
export const TabPlugin = definePlatePlugin('tab', {
  on: {
    keyDown: ({ event }) => {
      if (event.key !== 'Tab') return false;
 
      event.preventDefault();
 
      return true;
    },
  },
});

Use shortcuts when the key combination should call a plugin API, transform, or explicit handler.

components/editor/save-plugin.tsx
import { definePlatePlugin } from 'platejs/react';
 
export const SavePlugin = definePlatePlugin('save', {
  shortcuts: {
    draft: {
      keys: 'mod+s',
      handler: ({ event }) => {
        event.preventDefault();
 
        return true;
      },
    },
  },
});
components/editor/save-plugin.tsx
import { definePlatePlugin } from 'platejs/react';
 
export const SavePlugin = definePlatePlugin('save', {
  shortcuts: {
    draft: {
      keys: 'mod+s',
      handler: ({ event }) => {
        event.preventDefault();
 
        return true;
      },
    },
  },
});

API Calls

Plate keeps reads and writes separate. Read editor state with editor.read(...). Mutate the document with editor.update(...). Use editor.api.* for plugin services and host/runtime APIs, not document mutations.

editor-commands.ts
const text = editor.read((state) => state.text.string([]));
 
editor.update((tx) => {
  tx.marks.toggle('bold');
  tx.text.insert('Hello');
});
 
editor.api.debug.log(text);
editor-commands.ts
const text = editor.read((state) => state.text.string([]));
 
editor.update((tx) => {
  tx.marks.toggle('bold');
  tx.text.insert('Hello');
});
 
editor.api.debug.log(text);

Headless Code

Use createBaseEditor from platejs for non-React importers, serializers, transforms, and tests.

lib/headless-editor.ts
import { createBaseEditor } from 'platejs';
 
export const editor = createBaseEditor({
  initialValue: [
    {
      children: [{ text: 'Headless document.' }],
      type: 'paragraph',
    },
  ],
});
lib/headless-editor.ts
import { createBaseEditor } from 'platejs';
 
export const editor = createBaseEditor({
  initialValue: [
    {
      children: [{ text: 'Headless document.' }],
      type: 'paragraph',
    },
  ],
});

Related

  • Editor for editor creation options.
  • Plugin Components for replacing renderElement and renderLeaf.
  • Plugin Methods for .configure() and typed .extend() contributions.
  • Plugin Shortcuts for keyboard command wiring.
}