I need to store serialized content state into local storage. I'm trying to convert data and get it back using data conversion helpers. State contains some custom inline styles. This is a sample code:
var oldEditorState = this.state.editorState;
var editorState = RichUtils.toggleInlineStyle(oldEditorState, myCustomStyle);
editorState = RichUtils.toggleInlineStyle(editorState, 'BOLD')
var contentState = editorState.getCurrentContent();
var rawContent = DraftJs.convertToRaw(contentState);
var contentBlocks = DraftJs.convertFromRaw(rawContent);
var contentState = ContentState.createFromBlockArray(contentBlocks);
var nextEditorState = EditorState.createWithContent(contentState);
this.setState({editorState: nextEditorState});
Unfortunately this approach loses custom styles. But it works fine with predefined (e.g. BOLD). Why? How can i solve this problem?