Hi,
I'm trying to initialize text editor with some HTML. The problem is that the method "createWithContent" throws an error.
My code:
import {Editor, EditorState, convertFromHTML} from 'draft-js'
import React, { Component } from 'react'
export default class RTEEditor extends Component {
constructor(props) {
super(props);
this.state = { editorState: EditorState.createEmpty() }; //createWithContent(convertFromHTML(this.props.initialHtmlContent)) };
this.onChange = (editorState) => { this.setState({ editorState }); };
}
render() {
return <div>
<Editor editorState={this.state.editorState} onChange={this.onChange} ref="editor" />
</div>
}
}

What I also noticed, when I'm using "createWithContent" RTEEditor component constructor is called twice and first attempt is running without error but second call causes exception.
Using "createEmpty" function does not make two constructor calls and component is displayed properly.
You need to do the following:
EditorState.createWithContent(
ContentState.createFromBlockArray(
convertFromHTML(this.props.initialHtmlContent)
)
);
the answer from mitermayer is the solution. Thank you very much :)
Most helpful comment
You need to do the following: