React Simple WYSIWYG Editor

3.4.1 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import { useState } from 'react';
import Editor from 'react-simple-wysiwyg';

function MyRichTextEditor() {
  const [htmlContent, setHtmlContent] = useState('Write your <b>rich text</b> here!');

  // The onChange event provides an event object with e.target.value containing the HTML string.
  function handleChange(e: { target: { value: string } }) {
    setHtmlContent(e.target.value);
  }

  return (
    <div style={{ maxWidth: '800px', margin: '20px auto', padding: '15px', border: '1px solid #ddd', borderRadius: '8px' }}>
      <h2>My Simple Editor</h2>
      <Editor 
        value={htmlContent}
        onChange={handleChange}
        containerProps={{ style: { marginTop: '15px', border: '1px solid #ccc', borderRadius: '4px' } }}
        placeholder="Start typing..."
      />
      <p style={{ marginTop: '20px', fontSize: '0.9em', color: '#666' }}>
        Current HTML Output (for demonstration):
      </p>
      <pre style={{ background: '#f8f8f8', padding: '10px', borderRadius: '4px', overflowX: 'auto' }}>
        {htmlContent}
      </pre>
    </div>
  );
}

// To render this in a typical React application:
// import React from 'react';
// import ReactDOM from 'react-dom/client';
// const root = ReactDOM.createRoot(document.getElementById('root')!);
// root.render(<React.StrictMode><MyRichTextEditor /></React.StrictMode>);

view raw JSON →