logo

Unlock Rich Text Editing in Your React/Next.js Apps with DevExpress RichEdit: A Seamless Guide

VH CHAUDHARY
Unlock Rich Text Editing in Your React/Next.js Apps with DevExpress RichEdit: A Seamless Guide

In this blog post, we’ll explore how to seamlessly integrate the versatile DevExpress RichEdit component into your Next.js application. We’ll guide you through key steps, including:

  • Installation and Setup: Get DevExpress RichEdit up and running in your Next.js environment.
  • Data Handling: Learn how to effectively manage and retrieve updated document data within Next.js, ensuring a smooth user experience.
  • Custom Saving: Empower users to save their documents with a custom button, granting them greater control over their work.
  • Event Handling: Implement event handlers to capture essential events, such as document saving, and perform necessary actions.
  • Best Practices: Discover best practices for optimizing RichEdit integration within Next.js, ensuring optimal performance and maintainability.

Here’s a detailed guide with code snippets for integrating DevExpress RichEdit in Next.js:

1. Installation:

  • Install the DevExpress RichEdit package using npm or yarn:
npm install devexpress-richedit-react

2. Import Component:

  • Import the RichEdit component in your Next.js page or component:
import { RichEdit } from 'devexpress-richedit-react';

import 'devextreme-dist/css/dx.light.css';
import 'devexpress-richedit/dist/dx.richedit.css';

3. Implement Basic Usage:

  • Add the RichEdit component to your JSX, providing initial document content if needed:
function MyDocumentEditor() {
  const [documentContent, setDocumentContent] = useState('Initial document content');

return (
    <RichEdit
      value={documentContent}
      onChange={(e) => setDocumentContent(e.value)}
    />
  );
}

4. Handle Saving:

  • Trigger document saving using richEdit.saveDocument():
const handleSave = () => {
  richEdit.saveDocument(DevExpress.RichEdit.DocumentFormat.OpenXml);
};

5. Capture Saved Data:

  • Add an event handler for the Saving event to retrieve saved content:
richEdit.events.saving.addHandler((s, e) => {
  const savedContent = e.base64; // Base64-encoded document content
  console.log('Saved content:', savedContent);
  e.handled = true; // Prevent default saving behavior
  // Perform actions with saved content, e.g., send to server
});

6. Custom Saving Button:

  • Create a button to initiate saving:
<button onClick={handleSave}>Save Document</button>

7. Additional Considerations:

  • Styling: Customize the RichEdit component’s appearance using CSS or DevExpress themes.
  • Toolbar Customization: Adjust the toolbar options to suit your needs.
  • File Upload/Download: Integrate features for loading and saving documents from files.
  • Server-Side Interactions: Handle document saving and retrieval on the server side, if necessary.

For more intersting topics follow us on Medium.

About PySquad

PySquad works with businesses that have outgrown simple tools. We design and build digital operations systems for marketplace, marina, logistics, aviation, ERP-driven, and regulated environments where clarity, control, and long-term stability matter.
Our focus is simple: make complex operations easier to manage, more reliable to run, and strong enough to scale.