如题,官网的例子在这里=>https://facebook.github.io/draft-js/docs...
我想先看一下这个富文本编辑器组件的效果,所以copy了官方例子的代码,install以及webpack转义之后,在浏览器运行时却出错了。
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);
这是我例子的代码:
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() {
const {editorState} = this.state;
return <Editor editorState={editorState} onChange={this.onChange} />;
}
}
ReactDOM.render(
<MyEditor />,
document.getElementById('container')
);
错误的意思貌似是说子组件有问题?所以我改了一下代码:
render() {
const {editorState} = this.state;
return <div>子组件</div>;
}
这么写就没有报错了。奇怪了,难道官方提供的例子有问题吗?求用过draft-js的亲们指点...
其实一直找不出错误原因的时候我还用了另一种方法,也是按照官方的介绍来的,然而还是出错了...(问题=>https://segmentfault.com/q/1010000004870...)我只是想把这个组件用到我的项目中啊,怎么就这么难呢?求亲们指点...
这个 warning 对程序运行没有影响。React 由 0.14.0 升级到 15.0.0 就不显示这个 warning 了。