Draft.js editor initiate with text

Draft.js editor initiate with plain text content (for stackoverflow answer)

by Mikhail Shabrikov

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.0/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.1/immutable.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/draft-js/0.7.0/Draft.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/draft-js/0.10.0/Draft.js"></script>
<!-- Created for this stackoverflow answer - https://stackoverflow.com/a/47030806/5806646  -->
<div id="react-root"></div>

CSS

body {
  font-family: Helvetica, sans-serif;
}

.container-root {
  border: 1px solid black;
  padding: 5px;
  margin: 5px;
}

Babel + JSX

const {Editor, EditorState, ContentState} = Draft;

class Container extends React.Component {
  constructor(props) {
    super(props);

		const initialContent = 'Some text';
    const editorState = EditorState.createWithContent(ContentState.createFromText(initialContent));

    this.state = {
      editorState
    };
  }

  _handleChange = (editorState) => {
    this.setState({ editorState });
  }

  render() {
    return (
      <div className="container-root">
        <Editor 
          placeholder="Type"
          editorState={this.state.editorState}
          onChange={this._handleChange}
        />
      </div>
    );
  }
}

ReactDOM.render(<Container />, document.getElementById('react-root'))