React DOCX Editor: Add Word-Like Editing to Your Web App
A step-by-step guide to embedding a Word-like DOCX editor in a React app using the TX Text Control React component, with an ASP.NET Core service running the word processing engine behind a WebSocket. It covers the hosted service, middleware and CORS setup, a Base64 document endpoint, and loading the file with loadDocument().
Key points
- The React editor ships as the @txtextcontrol/tx-react-document-editor npm package and needs the TX Text Control backend reachable over a wss:// WebSocket.
- Program.cs registers the engine as an IHostedService, calls UseWebSockets() and UseTXWebSocketMiddleware(), and opens CORS for http://localhost:5173.
- A minimal controller returns the DOCX file as a Base64 string, which the client loads with window.TXTextControl.loadDocument() and StreamType.WordprocessingML.
- In Vite the component is wrapped, so the code resolves it with DocumentEditorModule.default ?? DocumentEditorModule.
- The built-in ribbon covers formatting, tables, merge fields, form elements, tracked changes and comments, and the JavaScript API lets you drive each of these from custom buttons.
- saveDocument() exports the edited document as PDF, DOCX, HTML or RTF.
TX Text Control has published a getting-started guide for putting a Word-like DOCX editor into a React front end while the heavy document processing stays in ASP.NET Core. The React side is the @txtextcontrol/tx-react-document-editor npm package, which renders the ribbon UI and talks to the server over a secure WebSocket; the back end hosts the vendor's word processing engine, which also renders PDF output so what users see matches what gets exported.
The walkthrough registers the engine as an IHostedService, adds UseTXWebSocketMiddleware() plus WebSockets and CORS for the Vite dev server, and exposes a controller that returns a DOCX file as a Base64 string. On the client, the component takes webSocketURL and editMode, waits for the global TXTextControl object, then calls loadDocument() with StreamType.WordprocessingML. Editing, tracked changes, form fields and save-to-PDF follow from there.
Real-world use
- A contract management portal where users open, redline with tracked changes and approve Word documents in the browser without installing Office.
- A reporting app that fills merge fields in a DOCX template from database data and exports the result to PDF for customers.
- An HR onboarding flow that renders a DOCX form with checkboxes and date pickers, collects the answers and stores the document back to blob storage.
Why it matters
It shows the real shape of a browser-based document editor: a thin React wrapper plus a stateful server engine you must host, license and secure, so the build-versus-buy and deployment decisions happen early.
Related stories
- Agent Framework builder skills for .NET and Python coding agentsMicrosoft Agent Framework Blog12 h ago
- The handler signature that kept growing: using [AsParameters] in minimal APIsDEV Community: #aspnetcore19 h ago
- Alba 9 arrives with host pooling for parallel integration testsJasperFx (Critter Stack) Blog2 d ago