DraftJS - contentState.getBlockMap is not a function
Asked Answered
S

1

4

I'm trying to save editorState to DB and show back to editor. For this thing, I followed this answer

Now, when I try to get current content and permanently save it using convertToRaw, It works fine. But when I try to use this data and transform raw to contentState using convertFromRaw I get following error:

Uncaught TypeError: contentState.getBlockMap is not a function

Here is my code to convert editorState from saved state:

{
    const convertedState = convertFromRaw(JSON.parse(value))
    const editorValue = EditorState.createWithContent(convertedState);
}

This way, it shows data in editor but when I type something to rich editor. It prompts :

Uncaught TypeError: contentState.getBlockMap is not a function

P.s. using draft-js: '0.10.5'

Sigmoid answered 12/2, 2018 at 9:9 Comment(1)
Show your full code.Greensand
V
6

EditorState is an Immutable Record that represents the entire state of a Draft.js editor, which includes the ContentState, but they are different things.

An EditorState object maintains undo and redo stacks comprised of ContentState objects.

What you are probably looking for is :

const convertedState = convertFromRaw(JSON.parse(value))
const editorValue = EditorState.createWithContent(convertedState.getCurrentContent());
Vaientina answered 3/10, 2018 at 18:2 Comment(1)
Thank you. Is this actually documented anywhere?Tortuosity

© 2022 - 2024 — McMap. All rights reserved.