You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
htmlToDraft(html: string) {
const { contentBlocks } = convertFromHTML(html);
return ContentState.createFromBlockArray(contentBlocks);
}
When I use the resulting content state to create an editor instance, it throws:
TypeError: contentState.getBlockMap(...).first(...) is undefined
createWithContent
./node_modules/draft-js/lib/EditorState.js:55
I run into the same problem. It's even true for empty tags like <p></p> or <em></em> - the contentBlocks array is empty then.
import{EditorState,ContentState,convertFromHTML}from'draft-js';functioncreateContentStateFromHtml(html){const{ contentBlocks, entityMap }=convertFromHTML(html);returnContentState.createFromBlockArray(contentBlocks,entityMap);}constcontent=createContentStateFromHtml('<p></p>');consteditor=EditorState.createWithContent(content);// throws TypeError: contentState.getBlockMap(...).first(...) is undefined// for now I am using this:consteditor=content.getBlockMap().size
? EditorState.createWithContent(content)
: EditorState.createEmpty();
So there is a difference between ContentState.createFromText called with an empty string and ContentState.createFromBlockArray using convertFromHTML on an empty string.
I have this:
TypeError: contentState.getBlockMap(...).first(...) is undefined
createWithContent
./node_modules/draft-js/lib/EditorState.js:55
52 | };
53 |
54 | EditorState.createWithContent = function createWithContent(contentState, decorator) {
getEditorBaseState
./components/RecipePage.tsx:164
161 | },
162 | ]);
163 |
The text was updated successfully, but these errors were encountered: