The ReactQuill component is the primary interface for integrating the Quill editor into a React application. It supports both controlled and uncontrolled modes using the value or defaultValue props.
Important Usage Notes:
- Value Types: The
value prop can be either a string (HTML) or a DeltaStatic object. If you use Deltas, ensure you use editor.getContents() to retrieve them, rather than passing the delta from onChange directly back into the value prop, which can cause infinite loops. - Editing Area: By default, the component renders a
<div> as the editing area. If you provide children, they must be a single React element. Note that <textarea> is not supported as a child; use a <div> instead. - Regeneration: Certain props like
modules, formats, bounds, theme, and children are considered "dirty props." Changing them will cause the entire Quill editor instance to be destroyed and re-instantiated.
import ReactQuill from 'react-quill';
// Controlled example
<ReactQuill
value="<p>Hello World</p>"
onChange={(content, delta, source, editor) => {
console.log(content);
}}
/>
// Uncontrolled example
<ReactQuill
defaultValue="<p>Initial content</p>"
/>