draft-js vs remirror vs slate
Rich Text Editors
draft-jsremirrorslateSimilar Packages:

Rich Text Editors

Rich text editors are essential tools in web development that allow users to create and edit content with complex formatting options. These libraries provide a framework for building customizable editors that can handle various text styles, media embedding, and more. Each library has its unique approach to handling document structures, state management, and extensibility, making them suitable for different use cases and developer preferences.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
draft-js490,55722,868-9546 years agoMIT
remirror27,7653,0141.21 MB2078 months agoMIT
slate031,6022.17 MB7002 months agoMIT

Feature Comparison: draft-js vs remirror vs slate

Customization

  • draft-js:

    Draft.js provides a robust API for creating custom block types and inline styles, allowing developers to tailor the editor to their specific needs. It supports a rich set of features like decorators and custom content blocks, making it easy to implement unique functionalities.

  • remirror:

    Remirror is built with extensibility in mind, offering a plugin system that allows developers to easily add or modify features. This makes it simple to create custom commands, schemas, and integrations, enabling a highly personalized editing experience.

  • slate:

    Slate offers unparalleled customization capabilities, allowing developers to define their own data models and rendering logic. This flexibility means you can create entirely unique editing experiences, but it also requires a deeper understanding of the library's architecture.

Performance

  • draft-js:

    Draft.js is optimized for performance, especially in React applications. It uses an immutable data structure to manage state, which helps in minimizing re-renders and improving responsiveness, making it suitable for applications with large documents.

  • remirror:

    Remirror is designed for performance with a focus on real-time collaboration. It leverages ProseMirror's efficient handling of document updates, ensuring smooth interactions even with complex editing tasks and multiple users.

  • slate:

    Slate's performance can vary based on how well the editor is configured. While it allows for deep customization, improper configurations can lead to performance issues. Developers need to be mindful of how they manage state and rendering to maintain efficiency.

Learning Curve

  • draft-js:

    Draft.js has a moderate learning curve, particularly for developers familiar with React. Understanding its concepts like ContentState and EditorState is crucial, but once grasped, it becomes easier to implement complex features.

  • remirror:

    Remirror is relatively easy to pick up, especially for those familiar with modern JavaScript. Its documentation is comprehensive, and the plugin system simplifies the process of adding new functionalities, making it accessible for developers of various skill levels.

  • slate:

    Slate has a steeper learning curve due to its flexibility and the need to understand its internal data structures. While powerful, it may require more time to master compared to other editors, especially for those new to building custom solutions.

Community and Ecosystem

  • draft-js:

    Draft.js has a strong community and is widely used in production applications, particularly in the Facebook ecosystem. However, it has fewer plugins and extensions compared to some newer libraries, which may limit out-of-the-box functionality.

  • remirror:

    Remirror boasts a growing community and an extensive ecosystem of plugins that enhance its capabilities. The active development and support make it a great choice for projects that require modern features and collaborative editing.

  • slate:

    Slate has a dedicated community and a variety of plugins available, but its ecosystem is not as extensive as some other libraries. The focus on customization means that developers often create their own solutions, which can lead to a more fragmented experience.

Integration

  • draft-js:

    Draft.js integrates seamlessly with React, making it an excellent choice for React-based applications. Its design aligns well with React's component model, allowing for easy state management and rendering.

  • remirror:

    Remirror is designed to work with various frameworks, including React, Vue, and Angular. This flexibility allows developers to integrate it into different projects without being tied to a specific technology stack.

  • slate:

    Slate is framework-agnostic, meaning it can be integrated into any JavaScript application. However, its customization capabilities require more effort to set up compared to libraries that are specifically built for certain frameworks.

How to Choose: draft-js vs remirror vs slate

  • draft-js:

    Choose Draft.js if you need a highly customizable and flexible editor that integrates well with React. It is particularly useful for applications that require a rich text editing experience with a focus on performance and extensibility.

  • remirror:

    Choose Remirror if you want a modern, extensible editor that supports a wide range of features out of the box, including collaborative editing. It is ideal for projects that require a rich set of plugins and a focus on developer experience.

  • slate:

    Choose Slate if you need complete control over the editor's behavior and structure. It is a highly customizable framework that allows you to define your own rendering logic and data structures, making it suitable for complex editing scenarios.

README for draft-js

draftjs-logo

Draft.js

Build Status npm version

Live Demo


Draft.js is a JavaScript rich text editor framework, built for React and backed by an immutable model.

  • Extensible and Customizable: We provide the building blocks to enable the creation of a broad variety of rich text composition experiences, from basic text styles to embedded media.
  • Declarative Rich Text: Draft.js fits seamlessly into React applications, abstracting away the details of rendering, selection, and input behavior with a familiar declarative API.
  • Immutable Editor State: The Draft.js model is built with immutable-js, offering an API with functional state updates and aggressively leveraging data persistence for scalable memory usage.

Learn how to use Draft.js in your own project.

API Notice

Before getting started, please be aware that we recently changed the API of Entity storage in Draft. The latest version, v0.10.0, supports both the old and new API. Following that up will be v0.11.0 which will remove the old API. If you are interested in helping out, or tracking the progress, please follow issue 839.

Getting Started

npm install --save draft-js react react-dom

or

yarn add draft-js react react-dom

Draft.js depends on React and React DOM which must also be installed.

Using Draft.js

import React from 'react';
import ReactDOM from 'react-dom';
import {Editor, EditorState} from 'draft-js';

class MyEditor extends React.Component {
  constructor(props) {
    super(props);
    this.state = {editorState: EditorState.createEmpty()};
    this.onChange = (editorState) => this.setState({editorState});
    this.setEditor = (editor) => {
      this.editor = editor;
    };
    this.focusEditor = () => {
      if (this.editor) {
        this.editor.focus();
      }
    };
  }

  componentDidMount() {
    this.focusEditor();
  }

  render() {
    return (
      <div style={styles.editor} onClick={this.focusEditor}>
        <Editor
          ref={this.setEditor}
          editorState={this.state.editorState}
          onChange={this.onChange}
        />
      </div>
    );
  }
}

const styles = {
  editor: {
    border: '1px solid gray',
    minHeight: '6em'
  }
};

ReactDOM.render(
  <MyEditor />,
  document.getElementById('container')
);

Since the release of React 16.8, you can use Hooks as a way to work with EditorState without using a class.

import React from 'react';
import ReactDOM from 'react-dom';
import {Editor, EditorState} from 'draft-js';

function MyEditor() {
  const [editorState, setEditorState] = React.useState(
    EditorState.createEmpty()
  );

  const editor = React.useRef(null);

  function focusEditor() {
    editor.current.focus();
  }

  React.useEffect(() => {
    focusEditor()
  }, []);

  return (
    <div onClick={focusEditor}>
      <Editor
        ref={editor}
        editorState={editorState}
        onChange={editorState => setEditorState(editorState)}
      />
    </div>
  );
}

Note that the editor itself is only as tall as its contents. In order to give users a visual cue, we recommend setting a border and a minimum height via the .DraftEditor-root CSS selector, or using a wrapper div like in the above example.

Because Draft.js supports unicode, you must have the following meta tag in the <head> </head> block of your HTML file:

<meta charset="utf-8" />

Further examples of how Draft.js can be used are provided below.

Examples

Visit http://draftjs.org/ to try out a basic rich editor example.

The repository includes a variety of different editor examples to demonstrate some of the features offered by the framework.

To run the examples, first build Draft.js locally. The Draft.js build is tested with Yarn v1 only. If you're using any other package manager and something doesn't work, try using yarn v1:

git clone https://github.com/facebook/draft-js.git
cd draft-js
yarn install
yarn run build

then open the example HTML files in your browser.

Draft.js is used in production on Facebook, including status and comment inputs, Notes, and messenger.com.

Browser Support

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
iOS Safari
iOS Safari
Chrome for Android
Chrome for Android
IE11, Edge [1, 2]last 2 versionslast 2 versionslast 2 versionsnot fully supported [3]not fully supported [3]

[1] May need a shim or a polyfill for some syntax used in Draft.js (docs).

[2] IME inputs have known issues in these browsers, especially Korean (docs).

[3] There are known issues with mobile browsers, especially on Android (docs).

Resources and Ecosystem

Check out this curated list of articles and open-sourced projects/utilities: Awesome Draft-JS.

Discussion and Support

Join our Slack team!

Contribute

We actively welcome pull requests. Learn how to contribute.

License

Draft.js is MIT licensed.

Examples provided in this repository and in the documentation are separately licensed.