首页 > draft-js组件,按着官方的例子写的却出了问题?

draft-js组件,按着官方的例子写的却出了问题?

如题,官网的例子在这里=>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://.com/q/1010000004870...)我只是想把这个组件用到我的项目中啊,怎么就这么难呢?求亲们指点...


这个问题好像在新版本中被fixed


这个 warning 对程序运行没有影响。React 由 0.14.0 升级到 15.0.0 就不显示这个 warning 了。


5和6掺和着写不好吧。你说的是多了组件两个字么?回去在项目里全局搜索下,看看哪里有这两个字。另外确定你运行的项目是你当前看到的项目才好。还有,提问的时候一定要把你的意思表达清楚,给老外看的话尽量不要写中文,会误导他们。箭头并不适用与描述问题,看不出来你的文字到底对应的是哪副图片。你的英语确实不好!

【热门文章】
【热门文章】