react-simple-wysiwyg is a lightweight and performant React component for creating basic WYSIWYG rich text editing experiences. Currently at version 3.4.1, it focuses on providing essential editing functionality without the extensive features and overhead of more complex editors like Slate.js, Tiptap, CKEditor, or TinyMCE. Its key differentiators include a small bundle size (~9kb, ~4kb gzipped), ease of configuration, and extensibility for simple custom buttons. The library explicitly states it does not sanitize HTML, provide advanced features like table or image editors, or alter HTML generated by the browser, requiring developers to handle these aspects externally (e.g., using `sanitize-html` for sanitization). While it utilizes the deprecated `document.execCommand` API, it justifies this by noting the lack of a modern alternative and its continued use by many popular WYSIWYG editors. The project appears to be actively maintained, with recent updates and open issues on GitHub.
npm install react-simple-wysiwygVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `react-simple-wysiwyg` as a controlled component within a React functional component, managing its HTML content using React's `useState` hook. It also shows basic styling and output display.
Be aware of this API's status. There is no direct fix provided by the library, as it's an upstream browser API issue. For applications requiring future-proof or more advanced editor capabilities, consider alternatives built on different technologies (e.g., ProseMirror, Lexical).
Integrate a robust HTML sanitization library (such as `sanitize-html`) into your application's data flow. Apply sanitization to any HTML content retrieved from the editor's `onChange` event before displaying it or persisting it to a database.
Evaluate your application's rich text requirements. If advanced features are crucial, explore more feature-rich WYSIWYG editors. If `react-simple-wysiwyg`'s core functionality is sufficient, custom solutions for specific missing features might be integrated, but understand the library's design limitations.
If clean and consistent HTML output is a critical requirement, you may need to implement a post-processing step to normalize or clean the HTML string received from the editor's `onChange` event, or opt for an editor that offers more explicit control over HTML generation.
Change the import statement from `import { Editor } from 'react-simple-wysiwyg';` to `import Editor from 'react-simple-wysiwyg';`Ensure the `value` prop is always provided and managed by React state, even if it's an empty string initially. For example, use `const [html, setHtml] = useState('');` to initialize the content as an empty string.Verify that all toolbar-related components are correctly imported as named exports (e.g., `import { Toolbar, BtnBold } from 'react-simple-wysiwyg';`) and are rendered as children of the `<Toolbar>` component within the `<Editor>`.