0.0.3 • Published 5 years ago

draft-go v0.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

draft-go

Grab and go draft.js editor

Install

npm install --save draft-go

Usage

import React, { Component } from 'react';
import GoEditor, { convertToHTML } from 'draft-go';

export default class Main extends Component {
  constructor(props) {
    super(props);

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

    this.preview = this.preview.bind(this);

    this.state = { previewHtml: '' };
  }

  preview() {
    const { editorState } = this.state;
    const contentState = editorState.getCurrentContent();
    const html = convertToHTML(contentState);
    this.setState({ previewHtml: html });
  }

  render() {
    const { previewHtml } = this.state;

    return (
      <div as="main" role="main">
        <button onClick={this.preview}>Preview</button>
        <GoEditor
          onChange={(editorState) => this.setState({editorState})}
        />
        <div style={{ marginTop: '2rem' }} dangerouslySetInnerHTML={{ __html: previewHtml }} />
      </div>
    )
  }
}
0.0.3

5 years ago

0.0.2

6 years ago

0.0.1

6 years ago