Typix LogoTypix
Getting Started

Editor Setup

Configure the editor with createEditorConfig, custom nodes, and initial content

Default behavior

When you use EditorRoot without a config prop, it creates a default configuration with:

  • Namespace: "typix-editor"
  • All default extension nodes (headings, lists, links, tables, code blocks, etc.)
  • The default Typix theme
  • Editable mode enabled
<EditorRoot>
  <EditorContent />
</EditorRoot>

This is sufficient for most use cases. For advanced control, read on.

Custom configuration

Use createEditorConfig to build a Lexical config object with Typix defaults.

import {
  EditorRoot,
  EditorContent,
  createEditorConfig,
  defaultExtensionNodes,
  defaultTheme,
} from '@typix-editor/react';

const config = createEditorConfig({
  namespace: 'my-editor',
  theme: defaultTheme,
  extensionNodes: defaultExtensionNodes,
  editable: true,
});

function MyEditor() {
  return (
    <EditorRoot config={config}>
      <EditorContent />
    </EditorRoot>
  );
}

Options

OptionTypeDefaultDescription
namespacestring"typix-editor"Unique namespace for the editor instance
themeEditorThemeClassesundefinedTheme classes for styling editor elements
extensionNodesReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>[]Custom nodes to register
editablebooleantrueWhether the editor is editable
onError(error: Error, editor: LexicalEditor) => voidconsole.errorError handler
initialStateSerializedEditorStateundefinedInitial content as serialized state
editorStateInitialEditorStateTypeundefinedAdvanced: direct Lexical editor state

If both initialState and editorState are provided, initialState takes priority.

Adding extension nodes

When you install extensions that provide custom nodes, add them to extensionNodes:

import { defaultExtensionNodes } from '@typix-editor/react';
import { CollapsibleContainerNode, CollapsibleContentNode, CollapsibleTitleNode } from '@typix-editor/extension-collapsible';
import { MentionNode } from '@typix-editor/extension-mention';

const config = createEditorConfig({
  extensionNodes: [
    ...defaultExtensionNodes,
    CollapsibleContainerNode,
    CollapsibleContentNode,
    CollapsibleTitleNode,
    MentionNode,
  ],
});

Default extension nodes

The defaultExtensionNodes array includes nodes for common content types:

NodeSourcePurpose
HeadingNode@lexical/rich-textH1–H6 headings
ParagraphNodelexicalParagraph blocks
TextNodelexicalInline text
QuoteNode@lexical/rich-textBlock quotes
ListNode@lexical/listOrdered, unordered, check lists
ListItemNode@lexical/listIndividual list items
LinkNode@lexical/linkHyperlinks
AutoLinkNode@lexical/linkAuto-detected links
CodeNode@lexical/codeCode blocks
CodeHighlightNode@lexical/codeSyntax-highlighted tokens
HashtagNode@lexical/hashtagHashtag tokens
OverflowNode@lexical/overflowOverflow containers
TableNode@lexical/tableTables
TableRowNode@lexical/tableTable rows
TableCellNode@lexical/tableTable cells

Initial content

You can provide initial content in several ways:

Via EditorRoot content prop

const savedContent = JSON.parse(localStorage.getItem('draft'));

<EditorRoot content={savedContent}>
  <EditorContent />
</EditorRoot>

Via createEditorConfig initialState

const config = createEditorConfig({
  initialState: {
    root: {
      children: [],
      direction: 'ltr',
      format: '',
      indent: 0,
      type: 'root',
      version: 1,
    },
  },
});

Listening for changes

EditorRoot provides two callbacks:

  • onContentChange — Receives SerializedEditorState (JSON), best for persistence
  • onChange — Receives raw EditorState, best for advanced state inspection
<EditorRoot
  onContentChange={(json) => saveToDatabase(json)}
  onChange={(editorState) => console.log(editorState)}
>
  <EditorContent />
</EditorRoot>

On this page