Skip to main content
Returns a Promise<string> with the output path. To keep the document in memory, for example to send it in an HTTP response or upload it, use renderToBuffer. It resolves to the file’s bytes as a Uint8Array:
Both functions accept the same options: For documents rendered from data that comes from outside the program, see Templates and testing.

Basic usage


Variables

Pass dynamic data to your document:

Variable component

A Variable that is not in variables and has no defaultValue rejects the render, so a missing value cannot produce an incomplete document. Pass null to render it empty on purpose.

useVariables hook

For more control:

Formatting


Async data

Components can read promises with React’s use() or load with React.lazy. Rendering waits until every suspended component has its data, so the document never contains a Suspense fallback.
Create the promise outside the component (or cache it) so each render reads the same promise. A rejected promise rejects render().

Error handling

render() and renderToBuffer() reject, without writing a file, when:
  • a component throws and no error boundary catches it;
  • a <Variable> was not provided and has no defaultValue;
  • an image cannot be loaded or is not PNG, JPEG, GIF or BMP;
  • an element is placed where Word cannot represent it, such as a <Section> outside <Document> or a <Paragraph> inside a <Link>.

Full example