New

docx-editor 1.x has shipped. Vue support, i18n, agents. Read the migration guide →

React

Props

Curated DocxEditorProps reference grouped by concern, with examples for the common patterns.

<DocxEditor> is configured through props. Groups below match how you'd reach for them in practice. The full generated reference (every prop, every type signature) is at /docs/1.x/api/react.

Document input

How the editor receives the document. Use documentBuffer for raw bytes; use document when you've already parsed.

PropTypeDescription
documentBufferDocxInput | nullArrayBuffer, Uint8Array, Blob, or File. Most common entry. null mounts an empty document.
documentDocument | nullPre-parsed -core document tree. Skip the parser if you already have one.
// From a fetch
const buf = await fetch("/template.docx").then((r) => r.arrayBuffer());
<DocxEditor documentBuffer={buf} />;
 
// From a file input
<input type="file" accept=".docx" onChange={(e) => setBuf(e.target.files?.[0] ?? null)} />
<DocxEditor documentBuffer={buf} />
 
// Empty document (mounts with no content; useful when collecting input from scratch)
<DocxEditor documentBuffer={null} />

Mode and read-only

Editing mode and the suggest/view/read-only states. Pair with onModeChange for controlled mode.

PropTypeDefaultDescription
modeEditorMode"editing""editing" | "suggesting" | "viewing". For read-only, use the readOnly boolean below.
onModeChange(mode) => voidControlled mode handler. Without it, the editor manages mode internally.
readOnlybooleanfalseIndependent of mode. Disables every input affordance (typing, toolbar buttons, dialogs) regardless of which mode is active.
const [mode, setMode] = useState<EditorMode>("editing");
 
<DocxEditor
  documentBuffer={buf}
  mode={mode}
  onModeChange={setMode}
/>;

"suggesting" wraps every edit as a tracked change. Use it for review flows.

Comments and collaboration

Pull author identity in, push comment state back out.

PropTypeDescription
authorstringAuthor name attached to new comments and tracked changes.
commentsComment[]Controlled comments. Pair with onCommentsChange.
onCommentsChange(comments) => voidFires on any comment mutation. Mirror into Y.Array for live sync.
onCommentAdd / onCommentResolve / onCommentDelete / onCommentReplycallbacksGranular events when you want to log or trigger side effects, not own state.
const [comments, setComments] = useState<Comment[]>([]);
 
<DocxEditor
  documentBuffer={buf}
  author="Jess Lin"
  comments={comments}
  onCommentsChange={setComments}
/>;

For Yjs-backed sync, see Realtime collaboration.

Toolbar and chrome

Toggle the built-in UI on or off.

PropTypeDefaultDescription
showToolbarbooleantrueToolbar visibility. Pass false and compose your own from /ui.
showZoomControlbooleantrueBottom-right zoom widget.
showRulerbooleanfalsePage ruler above the document body.
rulerUnit"inch" | "cm""inch"Ruler unit.
showMarginGuidesbooleanfalseFaint guides at page margins.
marginGuideColorstring"#c0c0c0"CSS color for the guides above.
showOutlinebooleanfalseDocument outline / table of contents drawer.
showOutlineButtonbooleantrueOutline toggle button in the toolbar.
initialZoomnumber1.0Starting zoom (1.0 = 100%).
fontFamiliesReadonlyArray<string | FontOption>.Constrain the font picker to a specific list.
// Headless-feeling editor: drop chrome and compose your own.
<DocxEditor documentBuffer={buf} showToolbar={false} showZoomControl={false} />

Title bar customization

The header strip is fully overridable.

PropTypeDescription
documentNamestringDisplay name in the title bar.
onDocumentNameChange(name) => voidFires when the user edits the title in-place.
documentNameEditablebooleanDefault true. Set false to lock the title.
renderLogo() => ReactNodeLeft-side logo slot. Default renders the document icon.
renderTitleBarRight() => ReactNodeRight-side slot. Wire your save status, share button, avatars.
toolbarExtraReactNodeExtra items appended to the toolbar.
<DocxEditor
  documentBuffer={buf}
  documentName={file.name}
  onDocumentNameChange={(name) => updateMetadata({ name })}
  renderTitleBarRight={() => <SaveIndicator dirty={dirty} />}
/>;

Callbacks

Lifecycle and integration hooks.

PropTypeDescription
onChange(doc: Document) => voidFires on every document mutation. Throttle for autosave.
onSave(buf: ArrayBuffer) => voidFires when the user invokes Save (Cmd+S or toolbar).
onSelectionChange(state: SelectionState | null) => voidSelection metadata for custom UI (active marks, paragraph style, etc.).
onError(error: Error) => voidErrors during parse or render. Send to your error tracker.
onFontsLoaded() => voidFired once the font set is ready. Use to defer measurement-sensitive UI.
onPrint / onCopy / onCut / onPaste() => voidNotification hooks for clipboard and print events.
<DocxEditor
  documentBuffer={buf}
  onChange={(doc) => debouncedAutosave(doc)}
  onSave={async (buf) => {
    await fetch("/api/documents/1", { method: "PUT", body: buf });
  }}
  onError={(err) => reportError(err)}
/>;

Styling

PropTypeDescription
themeTheme | nullColor and density token overrides.
classNamestringApplied to the editor root element.
styleCSSPropertiesInline styles on the root.
placeholderReactNodeRendered while there's no document content.
loadingIndicatorReactNodeRendered while the buffer is being parsed.
printOptionsPrintOptionsMargins, header/footer toggles for the print pipeline.
<DocxEditor
  documentBuffer={buf}
  className="rounded-lg shadow-md"
  loadingIndicator={<Spinner label="Loading document" />}
  placeholder={<EmptyState />}
/>;

i18n

PropTypeDescription
i18nLocaleStrings | PartialLocaleStringsLocale data from @eigenpal/docx-editor-i18n. See i18n page.
import pl from "@eigenpal/docx-editor-i18n/pl";
 
<DocxEditor documentBuffer={buf} i18n={pl} />;

Agents

PropTypeDescription
agentPanelAgentPanelOptionsWires a side panel slot. Pair with useDocxAgentTools.
<DocxEditor
  ref={editorRef}
  documentBuffer={buf}
  agentPanel={{ render: () => <AgentChatLog messages={messages} /> }}
/>;

Full setup in Agents → Live editor.

Plugins

PropTypeDescription
externalPluginsPlugin[]ProseMirror plugins appended to the editor's plugin list.
pluginOverlaysReactNodeAbsolutely-positioned overlay slot for plugin UI.
pluginSidebarItemsReactSidebarItem[]Sidebar entries contributed by plugins.
pluginRenderedDomContextRenderedDomContext | nullHand-off when you need plugin code to read editor DOM measurements.

See Plugins for the full plugin contract.

Ref methods

Imperative API exposed through forwardRef. Capture a DocxEditorRef and call methods directly when you need to drive the editor from outside React state.

import { useRef } from "react";
import { DocxEditor, type DocxEditorRef } from "@eigenpal/docx-editor-react";
 
const ref = useRef<DocxEditorRef>(null);
 
ref.current?.addComment({ paraId: "ABC12300", text: "Tighten this paragraph." });
ref.current?.scrollToParaId("DEF45600");
ref.current?.save(); // → ArrayBuffer

Common methods:

MethodReturnsWhat it does
save()Promise<ArrayBuffer>Serialize the current document to a .docx buffer.
addComment({ paraId, text })CommentAdd a comment anchored to a paragraph by w14:paraId.
proposeChange({ paraId, ... })voidInsert a tracked change.
findInDocument(query)FindMatch[]Search the document.
scrollToParaId(paraId)booleanScroll to a paragraph by w14:paraId. Returns false if not found.
scrollToPosition(pos)voidScroll to a raw ProseMirror position.
getDocument()DocumentSnapshot of the parsed tree.

The full method list with signatures is at /docs/1.x/api/react.

See also