🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Implementing Draft.js and converting rich text to Sanity portable text

16 replies
Last updated: May 18, 2023
Hey, can any one tell is there a way to implement draft js a rich text editor on the front end and send the data to sanity ?
May 18, 2023, 4:08 PM
you need to convert rich-text to portable-text similar to this https://github.com/portabletext/contentful-rich-text-to-portable-text
May 18, 2023, 4:28 PM
then it would work. but youd need to map the rich text correctly to sanitys portable text key for key. either that or you can upload the richtext as json but you wouldnt be able to edit it in the admin as easily. why not just use sanitys portable text editor from the sanity ui lib
May 18, 2023, 4:31 PM
thank you so much
May 18, 2023, 4:32 PM
can i dm u ?
May 18, 2023, 4:33 PM
no I dont have time for one on one.
May 18, 2023, 4:33 PM
ok
May 18, 2023, 4:34 PM
then can u tell what u are telling to use ?
then it would work. but youd need to map the rich text correctly to sanitys portable text key for key. either that or you can upload the richtext as json but you wouldnt be able to edit it in the admin as easily. why not just use sanitys portable text editor from the sanity ui lib
May 18, 2023, 4:34 PM
im saying using that repo I posted as a reference build your own draft rich text -> portable text converter
May 18, 2023, 4:35 PM
in other words, its possible but you need to use big brain science to make it work.
May 18, 2023, 4:36 PM
then is there a simple way ?
May 18, 2023, 4:37 PM
like I said you can upload the richtext from draft as json. which accepts any kind of json data(rich-text) to sanity
May 18, 2023, 4:38 PM
i just need a text editor on my front end and want to send the data to the admin studio
May 18, 2023, 4:38 PM
like I said you can upload the richtext from draft as json. which accepts any kind of json data(rich-text) to sanity
How to do it can u provide any resource ?
May 18, 2023, 4:42 PM
User’s answer here is what you’re looking for! You’ll set up your editor on your frontend, convert it to portable text then patch your data in your dataset.
If you don’t want to do that and just want to use the output from Drat directly, you’ll still need to submit a patch but you’ll also need to implement a Draft editor in your Studio.

You can learn more about patches by reading the resources in the documentation.
May 18, 2023, 4:53 PM
okey i got it now
May 18, 2023, 4:54 PM
thanks every one for help
May 18, 2023, 4:54 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?