suneditor-react provides a convenient React wrapper for the SunEditor WYSIWYG HTML editor. It simplifies integrating a rich text editor into React applications by encapsulating the underlying SunEditor library within a standard React component interface. The current stable version is 3.6.1, and the project appears to have an active release cadence with regular updates addressing bug fixes, performance improvements, and new features. A key differentiator is its explicit support for Next.js via dynamic imports to handle server-side rendering (SSR) compatibility. It also offers fine-grained control over editor configuration, including language settings, form name integration, and the ability to load only necessary plugins for performance optimization, differentiating it from simpler wrappers that might bundle all features by default. It requires the base `suneditor` package as a peer dependency, giving users control over its version.
npm install suneditor-reactVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to integrate `suneditor-react` into a Next.js application using dynamic imports, access the underlying SunEditor instance via a ref, set initial content, and handle content changes.
Review and adjust the parameter order in your callback functions for these specific upload events if you are upgrading from an earlier version and using these props. Refer to the official SunEditor documentation for the correct signature.
Ensure you run `npm install --save suneditor suneditor-react` or `yarn add suneditor suneditor-react` when setting up the package.
Always use Next.js's `dynamic` import with `ssr: false` to ensure the component is only loaded on the client-side. Refer to the 'Next.js' section in the package's README.
Pass a callback function to the `getSunEditorInstance` prop and store the returned `sunEditor` instance in a `useRef` hook. You can then interact with the core editor methods via this ref.
Override the `plugins` option within the `setOptions` prop to specify an array of desired plugin names. If `plugins` is not specified, all default plugins are loaded.
Wrap the `SunEditor` component with `next/dynamic` and set `ssr: false`. Example: `const SunEditor = dynamic(() => import('suneditor-react'), { ssr: false });`Ensure both `suneditor` and `suneditor-react` are installed (`npm install suneditor suneditor-react`) and that `SunEditor` is imported correctly as a default import: `import SunEditor from 'suneditor-react';`
Use the `getSunEditorInstance` prop to obtain the core SunEditor object and store it in a `useRef` hook. Ensure you check if the ref's `current` value is available before attempting to call methods on it.