DocsGo a little deeperCode examples
Quick install
Copy, paste, keep going

Code examples

Working examples for the things teams build first — a basic editor, controlled state, and saving a version.

Last updated

A basic editor

The smallest working setup: a provider, the editor, and your key.

components/BasicEditor.tsx
import { ConfigurableEditorWithAuth, EditorProvider } from 'eddyter';
import 'eddyter/style.css';

export default function BasicEditor() {
  return (
    <EditorProvider>
      <ConfigurableEditorWithAuth
        apiKey="your-api-key"
        onAuthSuccess={() => console.log('Ready!')}
      />
    </EditorProvider>
  );
}

Keep content in state

Seed the editor with initialContent and capture every edit with onChange.

components/EditorWithState.tsx
import { useState } from 'react';
import { ConfigurableEditorWithAuth, EditorProvider } from 'eddyter';
import 'eddyter/style.css';

export default function EditorWithState() {
  const [content, setContent] = useState('<p>Start writing...</p>');

  return (
    <EditorProvider>
      <ConfigurableEditorWithAuth
        apiKey="your-api-key"
        initialContent={content}
        onChange={setContent}
      />
    </EditorProvider>
  );
}

Save a version

Pass a correct per-document documentId — its own URL enables the fallback; in single-page apps where documents share a URL you must pass a real record id, or their histories collide. The toolbar toggle opens a panel to save, preview, and restore (server-backed, plan-gated).

The panel's own Save button covers existing records. Call saveVersion({ documentId }) from your Save button for new records and to snapshot from your own UI.

components/NoteEditor.tsx
import { useRef, useState } from 'react';
import {
  ConfigurableEditorWithAuth,
  EditorProvider,
  type EddyterEditorHandle,
} from 'eddyter';
import 'eddyter/style.css';

export default function NoteEditor({ note }) {
  const editorRef = useRef<EddyterEditorHandle>(null);
  const [content, setContent] = useState(note?.content ?? '');

  const handleSave = async () => {
    // 1) Persist content to YOUR backend first — returns the saved record { id }.
    const saved = await saveToYourBackend({ id: note?.id, content });

    // 2) Snapshot a version BEFORE unmounting the editor. saveVersion() reads
    //    the live editor state and no-ops once the editor unmounts.
    try {
      await editorRef.current?.saveVersion({ documentId: saved.id });
    } catch (err) {
      console.error('Version save failed:', err); // non-fatal
    }
  };

  return (
    <>
      <button onClick={handleSave}>Save</button>
      <EditorProvider>
        <ConfigurableEditorWithAuth
          // Remount when switching documents so initialContent reloads cleanly.
          key={note?.id ?? 'new-note'}
          ref={editorRef}
          apiKey="your-api-key"
          documentId={note?.id}
          initialContent={content}
          onChange={setContent}
        />
      </EditorProvider>
    </>
  );
}

Call it while the editor is mounted

saveVersion() reads the live editor state, so run your save flow before navigating away or closing the editor. See the ref prop in the API reference.