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'
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With