Tui.editor: How to use the editor in React?

Created on 2 Mar 2018  路  3Comments  路  Source: nhn/tui.editor

Version

1.0.4

Test Environment

Chrome, Mac, React

Current Behavior

This is probably a silly question, but I will dearly appreciate if you can provide a tutorial how to use the TUI Editor on React. I am new to the javascript world and know virtually nothing other than React.

BTW, the TUI Editor is awesome! It is the very best one that I have seen. Thank you for providing such a great editor!

Most helpful comment

I managed to make it work, hahaha. Below are my codes. Please let me know if there is another better approach.

import React, { Component } from 'react';
import Editor from 'tui-editor'
import 'tui-editor/dist/tui-editor.css'
import 'tui-editor/dist/tui-editor-contents.css'
import 'codemirror/lib/codemirror.css'
import 'highlight.js/styles/github.css'

class TestTuiEditor extends Component {

  componentDidMount() {
    let editor = new Editor({
      el: document.querySelector('#editSection'),
      initialEditType: 'wysiwyg',
      previewStyle: 'vertical',
      height: window.innerHeight - 20,
      events: {
        change: this.onChange
      }
    });

    this.setState({ editor });
  }

  onChange = (event) => {
    console.log(this.state.editor.getValue());
  }

  render() {
    return (
      <div id='editSection' />
    );
  }
}

export default TestTuiEditor;

All 3 comments

I managed to make it work, hahaha. Below are my codes. Please let me know if there is another better approach.

import React, { Component } from 'react';
import Editor from 'tui-editor'
import 'tui-editor/dist/tui-editor.css'
import 'tui-editor/dist/tui-editor-contents.css'
import 'codemirror/lib/codemirror.css'
import 'highlight.js/styles/github.css'

class TestTuiEditor extends Component {

  componentDidMount() {
    let editor = new Editor({
      el: document.querySelector('#editSection'),
      initialEditType: 'wysiwyg',
      previewStyle: 'vertical',
      height: window.innerHeight - 20,
      events: {
        change: this.onChange
      }
    });

    this.setState({ editor });
  }

  onChange = (event) => {
    console.log(this.state.editor.getValue());
  }

  render() {
    return (
      <div id='editSection' />
    );
  }
}

export default TestTuiEditor;

initialEditType should be markdown,then it work.

@dioscuroi did you try to register custom extensions while using this project with react?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tirli picture tirli  路  5Comments

Yeongjae-Shin picture Yeongjae-Shin  路  3Comments

aarangara picture aarangara  路  3Comments

koliyo picture koliyo  路  4Comments

mygyugyu picture mygyugyu  路  3Comments