Skip to content

Repository files navigation

react-docx

npm version Monthly npm downloads

JavaScript and React DOCX viewer/editor with pagination, editing, import/export, document review and thumbnails. It also opens legacy Word files and offers experimental, view-only support for OpenDocument text (.odt); see supported formats. The browser runtime uses the Rust/WASM parser from Duke Office.

Quick start

pnpm add @extend-ai/react-docx

React integrations require react and react-dom; the /vanilla entry bundles Preact.

import { DocxEditorViewer, useDocxEditor } from "@extend-ai/react-docx";

export function DocumentViewer() {
  const editor = useDocxEditor();
  return (
    <>
      <input type="file" accept=".docx" onChange={(event) => {
        const file = event.target.files?.[0];
        if (file) void editor.importDocxFile(file);
      }} />
      <DocxEditorViewer editor={editor} mode="read-only" defaultZoom="fit-width" />
    </>
  );
}

Use mode="edit" for editing and editor.exportDocx() for export. For a parsed document, use useDocxEditor({ document }). Vanilla apps use createDocxViewer from @extend-ai/react-docx/vanilla and call destroy() on teardown.

Full API and hooks · Vanilla API · Thumbnails

Integration notes

  • WASM loads lazily. Configure setWasmSource before the first parse/export for custom hosting; see WASM and Vite setup.
  • Built-in imports require a same-origin Web Worker by default. Pass useWorker to useDocxEditor or useDocxModel to permit or force main-thread parsing; parseDocxForViewer permits main-thread fallback unless useWorker: "required" is set. Layout and React rendering run on the main thread. See import worker.
  • Embedded fonts load by default. After changing caller fonts, call refreshDocxFontMetrics(); recreate standalone thumbnail renderers. See font handling.
  • Review mutations support limited text revisions and plain-text comment ranges. Unsupported or stale actions leave the document unchanged; review hooks and boundaries describe the contract.
  • OpenDocument text support (.odt, .ott, .odm, .otm, .oth, flat .fodt) is experimental and view-only; rendering coverage and layout fidelity may vary. editor.viewOnlyReason is set, the viewer renders read-only in any mode, and exportDocx()/getDocxBytes() are refused. What is and is not displayed.
  • Saved 3D previews remain visible; parseDocxForViewer(source, { include3dModels: true }) additionally exposes original assets and scene XML. Shared renderer coverage distinguishes rendering from preserved previews.

Development

Use Node.js from .nvmrc and pnpm 9.15.0; supported Node ranges are in package.json.

pnpm install --frozen-lockfile
pnpm dev
pnpm build
pnpm typecheck
pnpm test:unit
pnpm test:visual
Work Start here
Public viewer, controller and hooks packages/react-viewer
OOXML parts and normalized model packages/ooxml-core, packages/doc-model
Editing and DOCX export packages/editor-ops, packages/serializer
Pagination and layout packages/layout-engine, packages/layout-core
WASM build and Rust adapter packages/wasm, crates/docx-wasm
Manual and automated validation apps/playground, tests, Word fidelity harness

Parser fixes belong in Duke Office. Normal JS builds validate the committed WASM; runtime updates must include rebuilt bindings, lockfiles, provenance and notices. npm releases use Changesets; Rust and npm versions are independent. See playground deployment for build provenance.

Visual comparisons

Microsoft Word charts

Microsoft Word chart comparisons side by side

November 4, 2026, React DOCX 0.14.0: 155/157 charts rendered, with 28 pairs in this overview. Galleries, measurements and method retain differences and missing charts. Parser benchmarks measure native extraction separately from viewer layout.

Office Art

Microsoft Word and Rust Office Art: SmartArt, WordArt, 3D model previews, shapes, icons and ink

November 6, 2026: 30 native-adapter cases covering SmartArt, WordArt, 3D previews, shapes, icons and ink. These captures measure the shared renderer, not this npm release's pagination. Font substitution, curved text, shading and pencil texture remain limited.

WordArt and 3D shapes · Models and SmartArt · Icons and ink · Method and remaining gaps

Live demos

DOCX viewer with a paginated document and zoom controls

DOCX editor with a document and formatting toolbar

Click the screenshots for viewer/editor demos and integration docs. MIT license.

Releases

Packages

Used by

Contributors

Languages