> ## Documentation Index
> Fetch the complete documentation index at: https://docs.doconda.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How do I add a Word (DOCX) editor to a React app?

> Install @doconda/editor and render DocondaEditor: users open, edit and save the .docx in the browser, and you get it back with save() or onSave.

Install Doconda's editor plugin (`@doconda/editor`) and render `<DocondaEditor src={url} />` in a container with a
height. Users open the `.docx`, edit it and save it inside your site, and you get the edited file as bytes. The file
is opened and edited in the browser: it isn't uploaded anywhere to be edited.

## Steps

1. Get the plugin in the dashboard (**Editor**). It has a 7-day free trial; see
   [Licence and domains](https://docs.doconda.com/editor/license.md).
2. Install it with the command the dashboard gives you. It needs React 19 or later:

```bash theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
# .npmrc with the registry and token from the dashboard (Editor)
npm install @doconda/editor
```

3. Render the editor in a container with a height:

```tsx theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
import { DocondaEditor } from "@doconda/editor"

export function Edit({ url }: { url: string }) {
  return (
    <div style={{ height: 700, display: "flex" }}>
      <DocondaEditor src={url} licenseKey="ek_eu_…" className="flex-1" />
    </div>
  )
}
```

4. Get the edited file through a `ref`:

```tsx theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
import { useRef } from "react"
import { DocondaEditor, type EditorHandle } from "@doconda/editor"

const editor = useRef<EditorHandle>(null)

<DocondaEditor ref={editor} src={url} licenseKey="ek_eu_…" />

const bytes = await editor.current!.save() // Uint8Array with the edited .docx
```

`src` is a `.docx` the browser can download: from your site, or from a server that allows it with CORS. If you already
have the file in memory (for example, from an `<input type="file">`), pass it in `file` with its name in `fileName`.

## Save without losing changes

`onSave` receives the bytes when the user saves (Ctrl/Cmd+S or **File** → **Save**):

```tsx theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
<DocondaEditor
  src={url}
  licenseKey="ek_eu_…"
  onSave={(bytes) => upload(bytes)}
  onDirtyChange={(pending) => setNotice(pending ? "Unsaved" : "Saved")}
/>
```

Behavior to be aware of:

* While editing, the editor keeps a recovery copy in the browser for 7 days and offers it back if the tab closed
  without saving. `autosave={false}` turns it off.
* Closing or reloading the page with unsaved changes asks for confirmation. `warnOnClose={false}` turns it off.
* Whatever the editor doesn't touch is saved as is: styles, charts and parts of the file it can't edit are kept.

## What it edits in a Word file

Text and paragraph styles, fonts, colours, lists, indents, line spacing, borders and shading, tables, images, shapes,
text boxes, links, columns, header and footer, footnotes, comments, table of contents, and find and replace. It also
prints and saves as PDF (`save("pdf")`).

## FAQ

> [accordion] Does it also work with PowerPoint and Excel?
>
> Yes, the same component opens `.docx`, `.pptx` and `.xlsx`. The format comes from the link's extension; if it has
> none, pass `format` (`"word"`, `"slide"` or `"cell"`).

> [accordion] Do I need the licence key while developing?
>
> No. On `localhost`, `127.0.0.1` and `*.localhost` the editor always opens, with or without a key, and shows a
> "development licence" notice. In production it opens only on your licence's domains (up to 5, https only).

> [accordion] Can I choose which buttons show up?
>
> Yes. `toolbar` picks which buttons appear, in what order and when (`@table` shows a group only while a
> table is selected), and `false` in `statusBar` or `contextMenu` removes those parts. See [Customize](https://docs.doconda.com/editor/customize.md#toolbar).

> [accordion] What if I only want to display the document?
>
> Add `readOnly`. See [How do I show a Word file read-only in React?](https://docs.doconda.com/answers/docx-viewer-react.md).

## Related

* [Editor plugin](https://docs.doconda.com/editor/introduction.md): every prop, event and method.
* [Licence and domains](https://docs.doconda.com/editor/license.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.