experiencing problem in setting initial editor state , using createWithContent()
The "richTextDescription" is what stored in database as
{"blocks":[{"key":"cipnj","text":"Admore ","type":"header-one","depth":0,"inlineStyleRanges":[{"offset":0,"length":7,"style":"BOLD"}],"entityRanges":[],"data":{}},{"key":"3ncop","text":"jhdf","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":0,"length":4,"style":"color-rgb(44,130,201)"}],"entityRanges":[],"data":{}},{"key":"2ra8a","text":"no please work !!","type":"header-five","depth":0,"inlineStyleRanges":[{"offset":0,"length":17,"style":"color-rgb(44,130,201)"},{"offset":0,"length":17,"style":"BOLD"}],"entityRanges":[],"data":{}}],"entityMap":{}}
setting initial use state hook:
const [richTextDescription, setRichTextDescription] = useState(
content.richTextDescription
);
the state change method:
const onEditorStateChange = (editorState) => {
setEditorState(editorState);
setRichTextDescription(convertToRaw(editorState.getCurrentContent()));
};
here setting the editor state with createWithContent().
const [editorState, setEditorState] = useState({
editorState: EditorState.createWithContent(
convertFromRaw(JSON.parse(richTextDescription))
),
});
<Editor
initialEditorState={editorState}
onEditorStateChange={onEditorStateChange}
}}
/>
the following shows output fine
<div
dangerouslySetInnerHTML={{
__html: draftToHtml(JSON.parse(richTextDescription)),
}}
></div>
but the intial editor state which should show the editable text within editor is now showing. it shows blank