Revise Editor SDK menu

Quickstart

Install Revise, render a document in React, and export DOCX.

Install#

npm i revise

react, react-dom, yjs, and y-protocols are peer dependencies. For server-side usage, revise/server is included in revise (see seeding from your own server).

Requires React 18+ and Node 18+ (Node 20+ for revise/server). The editor is client-side only; in Next.js, wrap it in a "use client" component loaded via next/dynamic with ssr: false.

Render a document#

ReviseEditor manages one or more documents, each identified by a stable, host-owned id. source accepts DOCX, ODT, RTF, Markdown, plain text, or HTML (supported formats).

DocumentPane.tsx
import ReviseEditor, { type ReviseEditorHandle } from "revise";
import "revise/style.css";
import { useRef } from "react";

export default function DocumentPane({ file }: { file: File }) {
  const editor = useRef<ReviseEditorHandle | null>(null);

  return (
    <ReviseEditor
      initialDocuments={[{ id: "contract-1", title: "Contract", source: file }]}
      onReady={(handle) => {
        // Editor is mounted. Attach subscriptions here.
        editor.current = handle;
      }}
      onDocumentReady={() => {
        // Document is parsed. Document controllers are usable.
      }}
      onChange={(documentId, document) => {
        console.log(documentId, "now has", document.children.length, "blocks");
      }}
    />
  );
}

The editor fills its parent element. Give the container an explicit height (100vh, fixed height, or a flex/grid track).

Load on demand#

Lazy-load the editor module (and its CSS import) so it stays out of your main entry bundle:

TSX
import { lazy, Suspense } from "react";

const DocumentPane = lazy(() => import("./DocumentPane"));

export function Workspace({ file }: { file: File }) {
  return (
    <Suspense fallback={<p>Loading…</p>}>
      <DocumentPane file={file} />
    </Suspense>
  );
}

Export#

TypeScript
await editor.current.whenReady();
const blob = await editor.current.tools.exportDocx();

whenReady() resolves once a document finishes opening. exportDocx() returns a Blob with comments and tracked changes preserved.

Create a blank document#

TypeScript
import { createEmptyDocx } from "revise";

await editor.current.documents.open({
  id: crypto.randomUUID(),
  title: "Untitled",
  source: await createEmptyDocx(),
});

Example application#

reviseio/sdk-demo (live demo) is a standalone React app paired with a Node service using revise/server.

Next steps#