Skip to main content

Overview

createYooptaEditor is the factory function that creates a new Yoopta Editor instance. It initializes the editor with plugins, text formatting marks, and optional initial content.

Function Signature

function createYooptaEditor(opts: CreateYooptaEditorOptions): YooEditor

Parameters

opts
CreateYooptaEditorOptions
required
Configuration object for creating the editor

Return Value

editor
YooEditor
A fully initialized YooEditor instance with all methods and properties available. See Editor Methods for the complete API.

Usage Examples

Basic Setup

import { useMemo } from 'react';
import { createYooptaEditor } from '@yoopta/editor';
import Paragraph from '@yoopta/paragraph';
import HeadingOne from '@yoopta/headings/HeadingOne';
import { Bold, Italic } from '@yoopta/marks';

function MyEditor() {
  const editor = useMemo(() => createYooptaEditor({
    plugins: [Paragraph, HeadingOne],
    marks: [Bold, Italic],
  }), []);
  
  return <YooptaEditor editor={editor} />;
}

With Initial Content

const initialContent = {
  'block-1': {
    id: 'block-1',
    type: 'Paragraph',
    value: [
      {
        id: 'element-1',
        type: 'paragraph',
        children: [{ text: 'Hello world!' }],
        props: { nodeType: 'block' }
      }
    ],
    meta: { order: 0, depth: 0 }
  }
};

const editor = createYooptaEditor({
  plugins: [Paragraph],
  value: initialContent,
});

With All Available Plugins

import { createYooptaEditor } from '@yoopta/editor';
import Paragraph from '@yoopta/paragraph';
import { HeadingOne, HeadingTwo, HeadingThree } from '@yoopta/headings';
import Blockquote from '@yoopta/blockquote';
import Code from '@yoopta/code';
import { BulletedList, NumberedList } from '@yoopta/lists';
import Image from '@yoopta/image';
import Video from '@yoopta/video';
import Link from '@yoopta/link';
import { Bold, Italic, Underline, Strike, Highlight } from '@yoopta/marks';

const PLUGINS = [
  Paragraph,
  HeadingOne,
  HeadingTwo,
  HeadingThree,
  Blockquote,
  Code,
  BulletedList,
  NumberedList,
  Image,
  Video,
  Link,
];

const MARKS = [Bold, Italic, Underline, Strike, Highlight];

const editor = createYooptaEditor({
  plugins: PLUGINS,
  marks: MARKS,
});

Read-Only Mode

const editor = createYooptaEditor({
  plugins: [Paragraph, HeadingOne],
  value: existingContent,
  readOnly: true, // Prevents editing
});

Custom Editor ID

const editor = createYooptaEditor({
  id: 'my-custom-editor-id',
  plugins: [Paragraph],
});

console.log(editor.id); // 'my-custom-editor-id'

Type Definitions

CreateYooptaEditorOptions

type CreateYooptaEditorOptions = {
  id?: string;
  plugins: readonly YooptaPlugin<Record<string, SlateElement>>[];
  marks?: YooptaMark<any>[];
  value?: YooptaContentValue;
  readOnly?: boolean;
};

YooptaContentValue

type YooptaContentValue = Record<string, YooptaBlockData>;

type YooptaBlockData = {
  id: string;
  type: string;           // PascalCase: "Paragraph", "HeadingOne"
  value: SlateElement[];  // Array of Slate elements
  meta: {
    order: number;        // Block position in document
    depth: number;        // Nesting level (0 = top-level)
    align?: 'left' | 'center' | 'right';
  };
};

Important Notes

Always wrap createYooptaEditor in useMemo when using in React components to prevent creating new editor instances on every render.
The editor validates the initial value on creation. If the value is invalid, a console error will be logged and the editor will start with empty content.
Use TypeScript for better type safety and autocomplete when working with the editor API.

See Also

Build docs developers (and LLMs) love