Load & save designs

Getting started

Load & save designs

A design is a JSON document. Save it from the editor, store it in your own database, and load it back later, exactly the react-email-editor loop.

tsxStudio.tsx
const ref = useRef();

// Save, the design JSON to store in your DB
ref.current.editor.saveDesign((design) => {
  db.designs.save(id, design);
});

// Load, restore a saved design (existing Unlayer designs auto-convert)
ref.current.editor.loadDesign(design);
Load inside onReady so the editor is ready first: onReady={(u) => u.loadDesign(design)}.

loadDesign accepts either a MailKaro design or an existing Unlayer design, Unlayer JSON is converted on load, so your stored templates keep working.

Promises and timing

Called without a callback, saveDesign returns a promise of the design. Calls made before the editor is ready are queued and run once it is, and design:loaded fires after each loadDesign.

ts
const design = await ref.current.editor.saveDesign();
await db.designs.save(id, design);

What loading resets

loadDesign replaces the whole canvas and clears the undo history, so the user cannot undo back to the design that was there before. Picking from the template library is different: that one can be undone, see templates.

Unlayer designs

An Unlayer design is converted as it loads and keeps its own content width. saveDesign always returns MailKaro's format, so once a converted design is saved, your database holds the MailKaro version. Keep the original if you might need it. To save as the user edits, use change events.