jpuri / react-draft-wysiwyg

A Wysiwyg editor build on top of ReactJS and DraftJS. https://jpuri.github.io/react-draft-wysiwyg
MIT License
6.42k stars 1.16k forks source link

React, render html saved from draft-js (react-draft-wysiwyg) #627

Open ghost opened 6 years ago

ghost commented 6 years ago

I'm learning React: totally newbie.

If I save in DB the HTML directly from react-draft-wysiwyg (is it a best practice?) and then in a view page of my React SPA I retrieve HTML from DB through my API:

QUESTIONS:

imoris11 commented 6 years ago

@johnunclesam have you considered using a json formatted string instead ? I tried using the html output too, but soon realized it wasn't particularly a good idea to dangerouslySetInnerHTML thus I switched to saving my editor input as a string.

Like this onContentStateChange = (content) => { var input = JSON.stringify(content) this.setState({content:input}) }