unlayer / react-email-editor

Drag-n-Drop Email Editor Component for React.js
https://unlayer.com/
MIT License
4.62k stars 742 forks source link

Pure Function to render html #111

Open chungchi300 opened 4 years ago

chungchi300 commented 4 years ago

We store the design into the database in JSON with the Admin portal. How to use a pure function to render related html when I use it in the front end?

import {designToHtml} from 'react-email-editor';

function demo({design}){
          <div

              dangerouslySetInnerHTML={{
                __html: designToHtml(design)
              }}
            />

}
lidrissi commented 4 years ago

i dont think there is a solution, for us we store both html and json design into the database

chungchi300 commented 4 years ago

Agree, I also store both html and json as a workaround. And I think it increases the maintainability when we follow Single source of truth if we can store the JSON only and use the render function

chungchi300 commented 4 years ago

even an async render function is cool too.

adeelraza commented 4 years ago

@chungchi300 we do have a REST API that you can use to convert JSON to HTML. Check: https://docs.unlayer.com/reference#render