我怎样才能使用draftjs

时间:2016-04-07 07:11:38

标签: javascript reactjs

我想使用Facebook的draftjs组件,但我遇到了一些障碍。

import React from 'react';
import ReactDOM from 'react-dom';
import { Editor, EditorState } from 'draft-js';

class MyEditor extends React.Component{
    constructor(props) {
    super(props);
    this.state = {
        editorState: EditorState.createEmpty()
    };
    this.onChange = (editorState) => this.setState({ editorState });
}

render(){
        var {editorState} = this.state;
        return(
            <Editor editorState={ editorState } onChange={ this.onChange } />
        );
}
}

ReactDOM.render(
      <MyEditor />,
      document.getElementById('container')
);

这是我写的代码,但是=&gt;

Warning: A component is `contentEditable` and contains `children` managed by React. It is now your responsibility to guarantee that none of those nodes are unexpectedly modified or duplicated. This is probably not intentional.


console.error(message);

我按如下方式更改了代码,并成功了=&gt;

render(){
        var {editorState} = this.state;
        return(
            <div>富文本编辑器</div>
        );
}

enter image description here

但这就是为什么?

1 个答案:

答案 0 :(得分:0)

这已在react 15.0.0 Link中修复。