Draft.js is a JavaScript framework developed by Facebook for building rich text editors within React applications. It leverages an immutable data model, specifically `immutable-js`, to manage editor state, offering functional state updates and aggressive data persistence for scalable memory usage. The latest stable version is 0.11.7, released in August 2020. However, the project has since been formally archived by Facebook on GitHub in February 2023, making it read-only and indicating that it is no longer actively maintained. This means no further bug fixes, features, or security updates are expected. Key differentiators include its tight integration with React's declarative API for rendering, selection, and input behavior, and its extensible architecture allowing for a wide variety of rich text composition experiences, from basic styling to embedded media.
npm install draft-jsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates a basic Draft.js editor using React Hooks, including state management, focusing, and handling basic key commands like bold/italic via RichUtils.
Review the official Draft.js documentation on Entity API changes and update your `Entity` creation and management logic to use the new API structure.
For new projects, evaluate actively maintained alternatives like Lexical or Slate. For existing projects, understand the risks of using abandoned software and prepare to fork or migrate if critical issues arise.
Familiarize yourself with `immutable-js` concepts. For performance-critical applications with extensive content, profile editor behavior and consider optimizing custom components or exploring alternatives.
Ensure `import 'draft-js/dist/Draft.css';` (or equivalent CSS import) is present in your application's entry point or the component where the editor is used.
Avoid batching or delaying `EditorState` updates that are directly propagated to the `Editor` component. Ensure `EditorState` always updates immediately. Be aware that browser extensions can interfere, which is often beyond direct code control.
Ensure the ref (`editorRef.current` in Hooks or `this.editor` in classes) is checked for null/undefined before calling `focus()`. Use `React.useEffect` with an empty dependency array for initial focus or conditional rendering.
Add `import 'draft-js/dist/Draft.css';` to your application's entry file or the component where the Draft.js Editor is used.
Ensure `EditorState` updates are immediate and synchronous when passed to the `Editor` component. Avoid external DOM modifications within the `contentEditable` area. Consider using `EditorState.push` for controlled changes.
Install the necessary conversion library (e.g., `draft-js-export-html`, `draft-js-import-html`) using `npm install <package-name>` or `yarn add <package-name>`.