How to render a Draft.js block as a React Component with Next.js

Viewed 56

I use Draft.js for users to create blogposts, and I save the editor state on my database as json.

To display the blogpost as HTML to users, I use draftjs-to-html to convert the state into HTML.

The library display the image correct to the users, but I need those images to be optimized with Next/Image component.

If I make a custom renderer to instead of returning the <img> tag return the <Image /> tag from Next, at the HTML it's returned [Object object] and not the processed HTML.

So I tried to use therenderToString from react-dom/server like this: renderToString(<Image .../>) but I receive a plain javascript at the HTML, and not the expected result.

So in a nut shell what I need is to create a custom renderer that accepts a React component as a return.

I have also tried the draft-js-export-html library, but I have similar results.

0 Answers
Related