React HTML Editor (TinyMce)

ぐ巨炮叔叔 提交于 2019-11-30 08:32:53

问题


I was searching for an HTML Editor for React, but since I found nothing that works fine (I just need to format Text h1, h2, h3, p, bold and images [in base64])

At the end I decided to use Tiny Mce, which works fine. But only when the page gets opened for the first time. If I get to that page again. Without a browser relaod, then tinymce is not initialized. Do you know what react event will be triggered in such a situation. Here is my little wrapper so far:

/** @jsx React.DOM */
var React = require('react');

var TinyMceEditor = React.createClass({
    componentDidMount: function() {
        var that = this;
        tinymce.init({
            selector: "textarea.tiny-mce-editor",
            setup : function(editor) {
                editor.on('change', function(e) {
                    that.props.onChange(editor.getContent());
                });
            },
            plugins: [
                "lists link image charmap print preview anchor",
                "searchreplace code fullscreen",
                "insertdatetime media table contextmenu paste"
            ],
            toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
        });
        tinyMCE.get(that.props.lang + '-editor').setContent(that.props.html);
    },
    render:function(){
        return (
            <div>
                <textarea ref="text" className="tiny-mce-editor" id={this.props.lang + '-editor'} />
            </div>
        )
    }
});
module.exports = TinyMceEditor;

回答1:


To fix this I had to delete the TinyMce instance when unmounting.

componentWillUnmount: function() {
    tinymce.remove('#' + this.props.lang + '-editor');
}


来源:https://stackoverflow.com/questions/29169158/react-html-editor-tinymce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!