Thursday, June 6, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  90] [ 3]  / answers: 1 / hits: 25377  / 8 Years ago, fri, april 8, 2016, 12:00:00

I'm trying to persist draft-js's EditorContent to database then read and recreate the EditorContent object again.
But EditorContent.getPlainText() strips away rich text content. I don't know how else to do it.



How do I properly persist EditorContent?


More From » reactjs

 Answers
6

The getPlainText() method, as its name suggests, only returns the plain text without any rich formatting. You should use the convertToRaw() and convertFromRaw() functions to serialize and deserialize the contents of the editor.



You can import them this way if necessary: (assuming you are using ES6)



import {convertFromRaw, convertToRaw} from 'draft-js';


If you need to export HTML instead, see https://medium.com/@rajaraodv/how-draft-js-represents-rich-text-data-eeabb5f25cf2#9260 (not sure you can import the contents back from HTML, though)


[#62647] Wednesday, April 6, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rickjordond

Total Points: 100
Total Questions: 105
Total Answers: 90

Location: Sweden
Member since Mon, May 8, 2023
1 Year ago
rickjordond questions
;