I use Draft.js as editor in my website. I can save the editor text as json format in the Database.But i want to save json data as string/Html, but it's comes out in json format. Here is what i have done so far for saving the value as json format:
<Editor
blockStyleFn={getBlockStyle}
customStyleMap={styleMap}
editorState={this.state.editorState}
handleKeyCommand={this.handleKeyCommand}
onChange={this.onChange}
placeholder="Describe the requirements and skills needed for the job"
ref="editor"
spellCheck={true}
/>
<h4>Editor content as HTML</h4>
<pre>{this.state.editorContentHtml}</pre>
And this the function for showing the html code under editor:
this.onChange = editorState => {
this.setState({
editorState,
editorContentHtml: stateToHTML(editorState.getCurrentContent())
});
};
This is the snapshot of my editor
this is the result after retrieving editor data
I want to save the html result in database and also show it as html. Any help regarding this would be appreciated or if there is any other alternative way for retrieving data as String format.