How to build a React DOCX viewer: Preview and render Word files
Table of contents
This tutorial demonstrates how to build a React Word viewer using Nutrient Web SDK to display DOC/DOCX files directly in browsers without server-side processing. The implementation involves creating a React project with Vite, installing the SDK, copying library assets to the public directory, and creating a viewer component. The SDK converts Office documents to PDF client-side, enabling features like text editing, annotations, and signatures without requiring Microsoft Office software or licenses. Font substitutions are handled automatically when custom fonts aren’t available, and the viewer can be customized further with additional capabilities like document assembly and redaction.
In this blog post, learn how to build a React Word viewer using Nutrient Web SDK. You’ll render and preview DOC or DOCX files directly in your web browser using client-side processing (no server required).
This tutorial covers viewing — rendering a Word file so users can read it. If you need users to edit the document and export their changes, see how to integrate a DOCX editor in React and Next.js instead.
The image below shows what you’ll be building.

You can check out the demo to see it in action.
Opening and rendering Office documents in the browser
Nutrient Web SDK brings support for Word, Excel, and PowerPoint formats to your application, without you or your users needing any Microsoft Office software, Microsoft Office licenses, or third-party open source software. The technology works by converting an Office document to PDF directly in the browser using our Office-to-PDF conversion engine, and the document is then rendered in our JavaScript viewer.
Additional capabilities with Office-to-PDF conversion
After converting an Office document to PDF in the browser, you can add features to the PDF representation. Available features depend on your license and selected components:
- Text editing — Edit text in the converted PDF.
- Page manipulation — Organize documents by adding, removing, or rearranging pages.
- Annotations — Add text highlights, comments, or stamps.
- Adding signatures — Draw, type, or upload a signature on the converted PDF.
Requirements to get started
To get started, you’ll need:
- The latest version of Node.js(opens in a new tab).
- A package manager compatible with npm. This post contains usage examples for Yarn(opens in a new tab) and the npm(opens in a new tab) client (installed with Node.js by default).
Setting up a new React project with Vite
- To get started, create a new React project using Vite:
# Using Yarnyarn create vite nutrient-react-example --template react
# Using npmnpm create vite@latest nutrient-react-example -- --template react- Change to the created project directory:
cd nutrient-react-exampleAdding Nutrient to your project
- Add the Nutrient dependency:
npm i @nutrient-sdk/viewerpnpm add @nutrient-sdk/vieweryarn add @nutrient-sdk/viewer- Nutrient Web SDK loads its WebAssembly and supporting files from a local path, so you need to copy them to the public folder. Start by installing the required copy plugin:
npm install -D rollup-plugin-copy- Then, update your Vite configuration (
vite.config.ts) to copy the SDK’s asset files during build:
import { defineConfig } from 'vite';import react from '@vitejs/plugin-react';import copy from 'rollup-plugin-copy';
export default defineConfig({ plugins: [ copy({ targets: [ { src: 'node_modules/@nutrient-sdk/viewer/dist/nutrient-viewer-lib', dest: 'public/', }, ], hook: 'buildStart', }), react(), ],});Displaying a Word document
- Add the DOC or DOCX document you want to display to the public directory. You can use our demo document as an example.
- Render the Word document as a PDF representation using Nutrient Web SDK.
Basic usage in App.tsx:
import { useEffect, useRef } from 'react';
function App() { const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => { const container = containerRef.current; if (!container) return; // Give each effect run its own target, including in Strict Mode. const target = document.createElement('div'); target.style.height = '100%'; container.appendChild(target); let cancelled = false; let unload = () => {};
const setup = (async () => { const NutrientViewer = (await import('@nutrient-sdk/viewer')).default; if (cancelled) return; unload = () => NutrientViewer.unload(target); await NutrientViewer.load({ container: target, document: 'document.docx', baseUrl: new URL(import.meta.env.BASE_URL, window.location.origin).href, }); })().catch(error => { if (!cancelled) console.error('Failed to load document', error); });
return () => { cancelled = true; target.remove(); // Wait for a pending load before disposing of its instance. void setup.then(() => unload()); }; }, []);
return <div ref={containerRef} style={{ height: '100vh', width: '100%' }} />;}
export default App;- Start your development server:
# Using Yarnyarn dev
# Using npmnpm run devOnce the server is running, you can view the converted Word document in the browser.
A note about fonts
When you convert an Office document with custom fonts to a PDF, Nutrient Web SDK might not have access to these fonts due to licensing constraints. In this case, Nutrient typically replaces unavailable fonts with their equivalents — like Arial with Noto.
Adding even more capabilities
Once you’ve deployed your viewer, you can start customizing it to meet your specific requirements or easily add more capabilities. To help you get started, here are some of our most popular React.js guides:
- Instant synchronization
- Document assembly
- Page manipulation
- Editor
- Forms
- Signatures
- Redaction
- Document security
Conclusion
In this blog post, you learned how to build a Word viewer using React with Nutrient SDK.
Test the viewer with your Word files to check font substitution and layout before integrating it into your application.
To get started, you can either:
- Start your free trial to test out the library and see how it works in your application.
- Launch our demo to see the viewer in action.
Related reading
- How to build a React Excel viewer — Display XLS and XLSX spreadsheets in React
- How to build a React PowerPoint viewer — Display PPT and PPTX presentations in React
- How to build a PowerPoint viewer in JavaScript — Display PPT/PPTX files in the browser with Nutrient
- Open Excel files in the browser using JavaScript — Handle XLS and XLSX files without Microsoft Office
- Angular file viewer for PDFs and Office files — Build a multiformat viewer with Angular
- Top five document viewers for developers — Compare DOCX and PDF viewer libraries side by side
FAQ
Use Nutrient Web SDK to build a Word viewer in React, allowing you to open and view DOC or DOCX files directly in the browser.
Install Nutrient using yarn add @nutrient-sdk/viewer or npm install @nutrient-sdk/viewer. Then copy the library assets to the public directory.
Yes, on the PDF representation created from the Word file. You can export those changes as PDF; this viewer workflow doesn’t write them back to DOCX. Use Document Authoring when you need DOCX editing and export.