1
votes

We are using the draft editor and convertToRaw and convertFromRaw to save and load state from our DB.

For our testing I use factories to create demo data. And want a simple way to generate test data. Simple text is fine.

Is their a function hidden in the library that can help me out?

ideally I could call

textToRaw(`Here is some nice text`)

and that would output something like:

{\"blocks\":[{\"key\":\"4tu7v\",\"text\":\"Here is some nice text\",\"type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":[],\"entityRanges\":[],\"data\":{}}],\"entityMap\":{}}

1
afaik, a simple method built in to draft.js to do this for you does not exist but like the person who answered the question said, it should be reasonably simple to build your own!Rose Robertson

1 Answers

0
votes

you only need blocks and entityMap. that is simple I think.

convertFromRow({blocks: lines.map(line=>{type:'unstyled', value:line}), entityMap:{}})