-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to start with value from database (text) #25
Comments
Thanks for using this component! ...
import { convertFromHTML, ContentState, convertToRaw } from 'draft-js'
import MUIRichTextEditor from '../../'
const sampleMarkup = '<b>Bold text</b>, <i>Italic text</i><br/ ><br />Other text<br /><br /><a href="http://myurl.com">Some link</a>'
// 1. Convert the HTML
const contentHTML = convertFromHTML(sampleMarkup)
// 2. Create the ContentState object
const state = ContentState.createFromBlockArray(contentHTML.contentBlocks, contentHTML.entityMap)
// 3. Stringify `state` object from a Draft.Model.Encoding.RawDraftContentState object
const content = JSON.stringify(convertToRaw(state))
...
<MUIRichTextEditor
value={content}
/> I have updated the examples directory as well if you want to take a look. Hope this helps you out! |
Oh, I see, It worked! |
Sorry for bothering again @niuware ! Also, I noticed the onSave icon, I just want to trigger that event from a different button outside the editor. Thanks once again :) |
Hi @felipenmoura
Hope one of this options helps you out! |
Great, thanks, it helped a lot. |
Ops, accidentally reopened the issue! |
If I have a text in my database (an HTML markup), how can I load it into this component?
I couldn't find documentation on how to convert it!
The text was updated successfully, but these errors were encountered: