Props

Configure the React editor document, chrome, callbacks, fonts, and imperative ref.

Configure the editor

This example loads DOCX bytes, sets an author, and handles the save action:

import { useRef } from 'react';
import { DocxEditor, type DocxEditorRef } from '@docx-editor.dev/react';

interface ContractEditorProps {
  bytes: Uint8Array;
  upload: (buffer: ArrayBuffer) => Promise<void>;
}

export function ContractEditor({ bytes, upload }: ContractEditorProps) {
  const editorRef = useRef<DocxEditorRef>(null);
  return (
    <DocxEditor
      ref={editorRef}
      document={bytes}
      mode="edit"
      author="Jess Lin"
      onSave={async () => {
        const buffer = await editorRef.current?.save();
        if (buffer) await upload(buffer);
      }}
    />
  );
}

For generated signatures, see the React API reference.

Set props

Document

PropTypeDescription
documentDocumentSourceDOCX bytes, 'blank', or an existing DocumentHandle.
mode'edit' | 'view' | 'suggesting'Editing mode. Updates without a remount.
authorstringAuthor for later comments, replies, and tracked changes. Updates without a remount; existing revisions keep their authors.
localestringBCP 47 locale for regional date input and generated labels, Defaults to en-US. Updates without a remount.
zoomnumberFixed display scale. Updates without a remount.
zoomModeZoomMode | 'auto'Scale source. The default 'auto' fits the page width.
fieldResults'atomic' | 'editable''editable' allows editing saved field results. Defaults to 'atomic'. See Edit saved field results.
contentLockPolicyContentLockPolicy{ allowFormattingInLockedContent: true } allows formatting in content-locked controls. See Formatting content-locked controls.
lockedControlNavigation'characters' | 'atomic'Caret movement through a locked inline control: per character (default) or as one unit. See Caret movement.
modulesreadonly EditorModule[]Capability modules from @docx-editor.dev/pro, such as reviewModule().

Fonts

PropTypeDescription
fontsFontConfiguration | FontConfigurationFragment | FontResolverFont bytes or a resolver for text shaping and pagination. Each new value replaces the fonts without a remount.
onFontError(error: EditorFontError) => voidReports corrupt data, HTTP errors, or hash mismatches.

Wrap resolvers such as packagedFonts() in useFonts to keep one identity. For loading choices, see Fonts and measurement.

Dark mode

PropTypeDescription
colorMode'light' | 'dark' | 'system'Sets the chrome theme and a display transform on the canvas. 'system' follows the operating system.

colorMode does not change authored colors, saved output, or printing. See Dark mode.

Chrome and layout

PropTypeDescription
chromebooleanShows the packaged title bar and toolbar. Set false for the document surface only.
titlestringTitle-bar document name.
renderTitleBarLeft / renderTitleBarRight() => ReactNodeHost content in title-bar slots.
menuboolean | DocxEditorMenuPropsToggles or configures the menu bar.
navigationboolean | DocxEditorNavigationPropsToggles or configures the navigation pane.
rulersbooleanShows or hides both rulers.
hyperlinkPopupbooleanShows or hides the hyperlink popover.
contextMenuboolean | DocxEditorContextMenuPropsToggles or configures the context menu.
popupsDocxEditorPopupsReplaces automatic popups with definePopup(MyPopup) or render callbacks. See Customize popups.
loadingIndicatorReactNodeReplaces the loading spinner. See loading indicator.
openFailureboolean | DocxEditorOpenFailurePropsConfigures the dialog for a file that does not open. See open failures.
renderOpenFailureActions(context) => ReactNodeAdds buttons to that dialog, built from DocxEditor.OpenFailure.Action.
childrenDocxEditorChildrenExtra chrome inside the viewport after the pages, such as DocxEditor.UnsupportedElement components.
t(key, params?) => stringResolves live chrome and drawing labels.
i18nTranslationsLive chrome and drawing labels for this editor. See i18n.

Handle callbacks

PropPayloadDescription
onReadyeditor: EditorRuns after the editor and document surface mount.
onChangechange: DocumentChangeRuns after mutations with revision and identity changes. It does not receive bytes.
onSavenoneReplaces the packaged File > Save action. Read bytes through the ref.
onOpennoneReplaces the packaged File > Open action.
onTitleChangetitle: stringEnables title editing and receives each new title.
onFontErrorerror: EditorFontErrorReports typed font-resolution failures.
onRevisionMarkupChangesettings: ResolvedRevisionMarkupReceives revision markup settings proposed by the API or the markup dialog. Store them in revisionMarkup to accept them.

Use the ref

<DocxEditor> exposes DocxEditorRef through forwardRef:

const buffer = await editorRef.current?.save();
const editor = editorRef.current?.getEditor();
editorRef.current?.focus();
MethodReturnsDescription
save()Promise<ArrayBuffer | null>Serializes the document to .docx. Returns null when no document is loaded.
load(document)voidLoads DOCX bytes, 'blank', or a DocumentHandle.
getDocumentHandle()DocumentHandle | nullReturns the current document identity and revision.
getEditor()Editor | nullReturns the full editor facade.
exec(command, options?)ExecResultRuns a typed command. Options name a scope and a historyGroup.
snapshot(options?)EditorSnapshotReads the current facade snapshot.
focus()voidFocuses the document surface.

Limits

  • fieldResults, contentLockPolicy, lockedControlNavigation, and modules apply at creation. To change them, remount with a different React key.
  • Collaboration refuses fieldResults="editable" with a TypeError.
  • The drawing renderers from drawingModule() and reviewModule() serve every editor in the page. A remount does not remove them. See Advanced drawing rendering.
  • Without the review module, the editor preserves revisions and comments on save but renders only the final state.
  • If you hide hyperlinkPopup, mount a panel that calls useHyperlinkPopup(), or the Insert link controls stay disabled.
  • Author colors have no prop. Mount <DocxEditor.AuthorStyle /> or <DocxEditor.ColorByChangeType />. See Tracked changes.
  • To customize unsupported content, see custom unsupported-content components.

Next steps