Draft.js is a framework for building rich text editors in React, powered by an immutable model and abstracting over cross-browser differences.

Draft.js makes it easy to build any type of rich text input, whether you’re just looking to support a few inline text styles or building a complex text editor for composing long-form articles.

Installation #

Currently Draft.js is distributed via npm. It depends on React and React DOM which must also be installed.

npm install --save draft-js react react-domCopy the code

Usage #

import React from 'react'; import ReactDOM from 'react-dom'; import {Editor} from 'draft-js'; const MyEditor = React.createClass({ onChange(editorState) { this.setState({editorState}); }, render() { const {editorState} = this.state; return ; }}); ReactDOM.render( , document.getElementById('container') );Copy the code

Next, let’s go into the basics of the API and learn what else you can do with Draft.js.