0

please help me. I have a code like this, but there is a problem at the time of changing the state, the message error is 'Uncaught Error: Got unexpected null or undefined (...)'

var contentState, editorState, text;
text = this.state.text;
contentState = ContentState.createFromBlockArray(Draft.convertFromHTML(text));
editorState = EditorState.createWithContent(contentState);
this.setState({
  editorState: editorState
});
Tio Lampard
  • 1
  • 2
  • 4

1 Answers1

0

why not just copy codes from doc

const sampleMarkup =
  '<b>Bold text</b>, <i>Italic text</i><br/ ><br />' +
  '<a href="http://www.facebook.com">Example link</a><br /><br/ >' +
  '<img src="image.png" height="112" width="200" />';

const blocksFromHTML = convertFromHTML(sampleMarkup);
const state = ContentState.createFromBlockArray(
  blocksFromHTML.contentBlocks,
  blocksFromHTML.entityMap,
);

this.state = {
  editorState: EditorState.createWithContent(state),
};
Jiang YD
  • 3,205
  • 1
  • 14
  • 20
  • yes I've tried it, but there is an error like this "Uncaught TypeError: Can not read property 'map' of undefined (...)" – Tio Lampard Nov 30 '16 at 02:37