RebodocsDocs
Start3
What is Rebodocs
Getting started
Demos to run
Put it in your app8
React component
Headless: your own UI
A complete interface
Without a framework
Only to read: the viewer
Styling and Tailwind
Phones and touch
Accessibility
Documents8
Templates and variables
On a server: DOCX and PDF
Documents in an S3 bucket
Letterheads
Versions
Tracked changes
Fonts
Languages
Together2
Real-time collaboration
AI assistants (MCP)
Reference5
Packages
Components and hooks
Editor API
How it works
Status and roadmap
↑↓ to move↵ to openEsc to close26 pages

Reference Components and hooks

Components and hooks

Everything @rebodocs/react exports — four components, thirteen hooks, the functions beside them, and a way to use it without React.

tip: press ⌘K to jump to any prop or hook
Start here

Which one do I need?

Pick what you want to build. The editor on the right shows which part comes from Rebodocs and which part is yours.

From RebodocsYours, built with hooksNot shown
'use client';
import { DocsEditor } from '@rebodocs/react';

export function Receipt({ file }: { file: Uint8Array }) {
  return (
    <div className="h-screen">
      <DocsEditor docx={file} name="receipt.docx" onSave={save} />
    </div>
  );
}

Give it a height. The editor and the pages fill their container and scroll themselves. Use h-full, or flex-1 min-h-0 inside a column.

4 components

Components

Holds one document for its children. It draws nothing.

  • Wrap your own UI with it
  • Keep docx stable
  • Latest callback wins
Show
PROP
TYPE
WHAT IT DOES
docx
Uint8Array | ArrayBuffer
The document to open; an empty one without it.Recreates the document
unsaved
boolean
Whether docx has changes not saved yet, as a draft your app kept: dirty from the start.Read with docx
name
string
What the document is called, given to what is saved and exported. Follows its prop.
author
string
Who the person is: what their notes are signed with. Follows its prop.
locale
string
The language of the texts the library still has: the bar beside the selection, what a screen reader is told. 'es', 'en', or one in locales; left out, the browser's, or English. The whole page's, as setLocale. Follows its prop.
locales
Record<string, Texts>
More languages, or other words for these, as { fr: texts }; the Chinese ones are in @rebodocs/editor/locales.
letterhead
Blob | { bytes, type } | string | null
A PNG or JPG to use as letterhead, as a file, its bytes or its address; null for none.
fonts
FontSource[]
Typefaces of your own, each with its family and its file. For the whole page; one added later is loaded then.
embedFonts
boolean | 'subset'
Whether the DOCX carries the fonts of fonts its text uses, when their licence lets it: whole unless false, or cut down to the characters used with 'subset'. Follows its prop.
spellcheck
SpellChecker
What marks the words spelled wrong, with a red wave, and offers what they could be: createSpellChecker with the dictionaries you give, or one of your own. Follows its prop.
theme
'light' | 'dark' | 'auto'
The colours of what the editor draws around the pages and the menus it shows: light as it comes, dark, or 'auto' for the system's. Follows its prop.
language
string
The language the text is in, as a tag ('es-MX'), written in the DOCX for spelling and so Word does not guess one, and the language variables are filled in (dates, numbers). Left out, the one the file says, or else the interface's with the browser's region; the person can choose another at the foot of the editor. Follows its prop.
onSave
(docx, name) => void
Called on ⌘S and on docs.save(). Keeping the file is yours to do.Adding or removing it recreates the document
onChange
(editor) => void
Called when the document changes.
onError
(message) => void
Told what went wrong; an alert without it.
onLinkKey
() => void
Answers ⌘K.
onFindKey
(replace) => void
Answers ⌘F and ⌘H; replace is true for ⌘H.
bubble
boolean
true for the bar beside the selection. See useDocsBubble.Read only at creation
slash
boolean | { builtIns?, commands? }
The menu a “/” brings up; with settings, which of its commands it keeps and your own. Its variable and note need bubble too.Read only at creation
variableSuggestions
boolean | { variables?, fromDocument?, allowNew? }
The list “{{” brings up, of the variables.Read only at creation
forms
boolean
Marking areas that can be changed from the bubble and the “/” menu.Read only at creation
collab
{ url, room, ticket? }
The document is a shared room on your collaboration server.Changing the room recreates the document
onCollab
(state, peers) => void
Called when the connection, or who is on the document, changes.
Why did my document reset?

The document is made again — and what was typed and not saved is gone — when docx changes, when the room of collab does (its url, room or ticket), or when there is an onSave where there was none, or the other way round. Keep docx the same value between renders: a Uint8Array held in state, not one built in the body of the component. The functions you pass may be new at each render; the last one given is the one called.

USE IT

// State a key must reach lives outside the provider, or in a child of it.
function Editor({ file }: { file: Uint8Array }) {
  const [finding, setFinding] = useState(false);
  return (
    <DocsProvider docx={file} name="contract.docx" onSave={upload} onFindKey={() => setFinding(true)}>
      <MyToolbar />
      {finding && <FindBar onClose={() => setFinding(false)} />}
      <DocsSurface className="h-full" />
    </DocsProvider>
  );
}
13 hooks

Hooks

Use them inside a DocsProvider to build your own interface. Pick one and play with it — the values on the right are what the hook returns.

useDocs()

DocumentOpen the full demo →

What every piece of an interface starts from: what to show, what buttons call, and the document as a whole.

Try it

Opening the editor…

What the hook returns — live

…

All it gives you

ready
False on the server and until the pages are on the page
state
What to show, as plain values — neutral until ready
commands
What buttons call: toggleMark(mark), setRunProps(props)…
docs
save(), download(), exportDocx(), openFile(), share(), setName()…
editor
The Editor itself — exportPdf(), exportMarkdown()…

Taking it apart

const { ready, state, commands, docs, editor } = useDocs();

Colours are hex without #, sizes are points. Each command gives the keyboard back to the document.

Use it

The piece running above, as its file has it: it goes anywhere inside a DocsProvider.

import { useDocs } from '@rebodocs/react';

const button = 'rounded-md border border-neutral-300 bg-white px-2.5 py-1 text-sm aria-pressed:bg-blue-100 disabled:opacity-40';

function Bold() {
  const { state, commands } = useDocs();
  return (
    <button className={`${button} font-bold`} aria-pressed={state.bold} onClick={() => commands.toggleMark('bold')}>
      B
    </button>
  );
}

function FontSize() {
  const { state, commands } = useDocs();
  return (
    <select aria-label="Font size" className={button} value={state.fontSize} onChange={(e) => commands.setRunProps({ fontSize: Number(e.target.value) })}>
      {[10, 11, 12, 14, 18, 24, 26].map((size) => (
        <option key={size}>{size}</option>
      ))}
    </select>
  );
}

function Save() {
  const { state, docs } = useDocs();
  return (
    <>
      <button className={button} disabled={!state.dirty} onClick={() => docs?.save()}>
        Save
      </button>
      <button className={button} disabled={!docs} onClick={() => docs?.download()}>
        Word
      </button>
    </>
  );
}

Languages and fonts

Not hooks, but used beside them: the language of what the library writes, and the fonts there are. See languages and fonts.

setLocale(code)getLocale()onLocaleChange(fn)addLocale(code, texts)locales()messages(locale)t(key)plural(key, n)fontFamilies()addFont(source)addFonts(sources)onFontsChange(fn)createSpellChecker(options)

Versions and assistants

With versions on DocsEditor, the side panel compares and goes back. To draw that panel yourself, or to open a DOCX as one more change of a shared room, use these; createAssistantChat puts Claude in a chat of your own, working on the document. See versions and AI assistants.

createVersionView(editor, versions)loadVersion(versions, id)compareDocs(before, after)createAssistantChat(editor, options)

Without React

mountDocs (from @rebodocs/react/mount) puts the whole editor in an element and gives back a handle with destroy(). createDocs puts only the pages, with state(), commands, editor, subscribe(fn) and setKeys.

Without a framework →