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
| Prop | Type | Description |
|---|---|---|
document | DocumentSource | DOCX bytes, 'blank', or an existing DocumentHandle. |
mode | 'edit' | 'view' | 'suggesting' | Editing mode. Updates without a remount. |
author | string | Author for later comments, replies, and tracked changes. Updates without a remount; existing revisions keep their authors. |
locale | string | BCP 47 locale for regional date input and generated labels, Defaults to en-US. Updates without a remount. |
zoom | number | Fixed display scale. Updates without a remount. |
zoomMode | ZoomMode | '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. |
contentLockPolicy | ContentLockPolicy | { 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. |
modules | readonly EditorModule[] | Capability modules from @docx-editor.dev/pro, such as reviewModule(). |
Fonts
| Prop | Type | Description |
|---|---|---|
fonts | FontConfiguration | FontConfigurationFragment | FontResolver | Font bytes or a resolver for text shaping and pagination. Each new value replaces the fonts without a remount. |
onFontError | (error: EditorFontError) => void | Reports 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
| Prop | Type | Description |
|---|---|---|
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
| Prop | Type | Description |
|---|---|---|
chrome | boolean | Shows the packaged title bar and toolbar. Set false for the document surface only. |
title | string | Title-bar document name. |
renderTitleBarLeft / renderTitleBarRight | () => ReactNode | Host content in title-bar slots. |
menu | boolean | DocxEditorMenuProps | Toggles or configures the menu bar. |
navigation | boolean | DocxEditorNavigationProps | Toggles or configures the navigation pane. |
rulers | boolean | Shows or hides both rulers. |
hyperlinkPopup | boolean | Shows or hides the hyperlink popover. |
contextMenu | boolean | DocxEditorContextMenuProps | Toggles or configures the context menu. |
popups | DocxEditorPopups | Replaces automatic popups with definePopup(MyPopup) or render callbacks. See Customize popups. |
loadingIndicator | ReactNode | Replaces the loading spinner. See loading indicator. |
openFailure | boolean | DocxEditorOpenFailureProps | Configures the dialog for a file that does not open. See open failures. |
renderOpenFailureActions | (context) => ReactNode | Adds buttons to that dialog, built from DocxEditor.OpenFailure.Action. |
children | DocxEditorChildren | Extra chrome inside the viewport after the pages, such as DocxEditor.UnsupportedElement components. |
t | (key, params?) => string | Resolves live chrome and drawing labels. |
i18n | Translations | Live chrome and drawing labels for this editor. See i18n. |
Handle callbacks
| Prop | Payload | Description |
|---|---|---|
onReady | editor: Editor | Runs after the editor and document surface mount. |
onChange | change: DocumentChange | Runs after mutations with revision and identity changes. It does not receive bytes. |
onSave | none | Replaces the packaged File > Save action. Read bytes through the ref. |
onOpen | none | Replaces the packaged File > Open action. |
onTitleChange | title: string | Enables title editing and receives each new title. |
onFontError | error: EditorFontError | Reports typed font-resolution failures. |
onRevisionMarkupChange | settings: ResolvedRevisionMarkup | Receives 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();| Method | Returns | Description |
|---|---|---|
save() | Promise<ArrayBuffer | null> | Serializes the document to .docx. Returns null when no document is loaded. |
load(document) | void | Loads DOCX bytes, 'blank', or a DocumentHandle. |
getDocumentHandle() | DocumentHandle | null | Returns the current document identity and revision. |
getEditor() | Editor | null | Returns the full editor facade. |
exec(command, options?) | ExecResult | Runs a typed command. Options name a scope and a historyGroup. |
snapshot(options?) | EditorSnapshot | Reads the current facade snapshot. |
focus() | void | Focuses the document surface. |
Limits
fieldResults,contentLockPolicy,lockedControlNavigation, andmodulesapply at creation. To change them, remount with a different Reactkey.- Collaboration refuses
fieldResults="editable"with aTypeError. - The drawing renderers from
drawingModule()andreviewModule()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 callsuseHyperlinkPopup(), 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
- React examples: Automate an open editor.
- React composition: Build your own chrome.
- React API reference: Generated signatures.