# React DOCX editor

Requires Node.js 22 or newer. Run `npm install`, then `npm run dev`. Open the localhost URL Vite prints. Use `npm run build` to build the project.

SuperDoc 2.35.0, React 19.3.1 and Vite 6.4.5. Direct dependencies are pinned.

Edit the public agreement, add a comment or suggest a change, and download a DOCX. Reopen the saved file to check the result. The App component owns initialization, error status, export and unmount cleanup.

The sample has no analytics, model calls or collaboration server. Collaboration needs a provider. Your application supplies identity, access, storage and any model integration.

[React guide](https://www.superdoc.dev/react-docx-editor) · [Documentation](https://docs.superdoc.dev/editor/quickstart/) · [AGPLv3 and licensing](https://docs.superdoc.dev/editor/license/)

## Complete source

### examples/react-editor/App.jsx

```jsx
import React, { useEffect, useRef, useState } from 'react';
import { SuperDoc } from 'superdoc';
import 'superdoc/style.css';
import './style.css';

export function App() {
  const host = useRef(null);
  const toolbar = useRef(null);
  const instance = useRef(null);
  const [ready, setReady] = useState(false);
  const [busy, setBusy] = useState(false);
  const [status, setStatus] = useState('Opening the public sample…');
  useEffect(() => {
    let disposed = false;
    const editor = new SuperDoc({
      selector: host.current,
      document: '/SuperDoc.docx',
      documentMode: 'editing',
      telemetry: { enabled: false },
      ui: { toolbar: { container: toolbar.current, responsiveTo: 'container' } },
      onReady: () => {
        if (disposed) return;
        setReady(true);
        setStatus('Ready. Edit, comment or suggest changes, then download a copy.');
      },
      onException: () => { if (!disposed) setStatus('The document could not be opened. Reload to try again.'); },
    });
    instance.current = editor;
    return () => {
      disposed = true;
      instance.current = null;
      editor.destroy();
    };
  }, []);
  async function download() {
    if (!ready || busy || !instance.current) return;
    setBusy(true);
    try {
      await instance.current.export({ exportType: ['docx'], exportedName: 'reviewed-agreement', triggerDownload: true });
      setStatus('DOCX downloaded. Reopen the saved file to check your edits.');
    } catch { setStatus('Download failed. Please try again.'); }
    finally { setBusy(false); }
  }
  return <main className="react-editor-app">
    <header><h1>Word editing in React</h1><p>Edit the included public agreement, add a comment or suggest an edit, then export a Word file.</p>
      <button disabled={!ready || busy} onClick={download}>{busy ? 'Preparing…' : 'Download DOCX'}</button>
      <p role="status">{status}</p>
    </header>
    <div ref={toolbar} className="react-editor-toolbar" />
    <div className="react-editor-document"><div ref={host} id="react-editor-host" /></div>
    <footer><a href="https://www.superdoc.dev/react-docx-editor">React integration guide</a> · <a href="https://docs.superdoc.dev/editor/quickstart/">Documentation</a> · <a href="https://docs.superdoc.dev/editor/license/">Licensing</a></footer>
  </main>;
}
```

### examples/react-editor/main.jsx

```jsx
import React from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './App.jsx';
createRoot(document.getElementById('root')).render(<App />);
```

### examples/react-editor/index.html

```html
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>React DOCX Editor Example | SuperDoc</title><meta name="description" content="A complete React DOCX editor example with comments, tracked changes and Word export."/><link rel="canonical" href="https://www.superdoc.dev/examples/react-editor/index.html"/><link rel="alternate" type="text/markdown" href="/examples/react-editor.md"/></head><body><div id="root"><main><h1>Word editing in React</h1><p>Edit the included public agreement, add a comment or suggest an edit, then export a Word file. The interactive editor loads with JavaScript.</p><p><a href="/examples/react-editor.md">Complete React source</a> · <a href="/examples/react-editor.zip">Download the React project</a> · <a href="/SuperDoc.docx">Public agreement DOCX</a> · <a href="/react-docx-editor">React integration guide</a></p></main></div><script type="module" src="./main.jsx"></script></body></html>
```

### examples/react-editor/style.css

```css
body { margin: 0; background: #f1f5f9; color: #0f172a; font-family: system-ui, sans-serif; }
header, footer { padding: 1.5rem; background: white; }
header h1 { margin-top: 0; }
button { padding: .75rem 1rem; cursor: pointer; background: #4f46e5; color: white; border: 0; border-radius: .5rem; font: inherit; }
button:disabled { opacity: .5; cursor: wait; }
.react-editor-toolbar { position: sticky; top: 0; z-index: 10; background: white; }
.react-editor-document { min-height: 70vh; overflow: auto; }
footer a { display: inline-flex; min-height: 44px; align-items: center; }

/* Keep the page stable while the native toolbar recalculates its overflow menu.
   The document remains horizontally scrollable inside its own viewport. */
.react-editor-app { min-width: 0; overflow-x: clip; }
```

### package.json

```javascript
{
  "name": "superdoc-react-editor",
  "private": true,
  "version": "1.0.0",
  "type": "module",
  "engines": {
    "node": ">=22"
  },
  "scripts": {
    "dev": "vite --open /examples/react-editor/",
    "build": "vite build"
  },
  "dependencies": {
    "superdoc": "2.35.0",
    "react": "19.3.1",
    "react-dom": "19.3.1"
  },
  "devDependencies": {
    "vite": "6.4.5"
  }
}
```

### vite.config.js

```javascript
import { defineConfig } from 'vite';
export default defineConfig({ optimizeDeps: {exclude: ['@superdoc/docx-engine'], include: ['vue']}, resolve: {dedupe: ['vue']}, build: {rollupOptions: {input: 'examples/react-editor/index.html'}} });
```

[Download complete project](https://www.superdoc.dev/examples/react-editor.zip)
[Public sample DOCX](https://www.superdoc.dev/SuperDoc.docx)
