Skip to main content
Version: Latest

React Component

Installation

npm install react-email-editor

Basic usage

src/EmailComponent.jsx
import React, { useRef } from 'react';
import EmailEditor from 'react-email-editor';

export default function EmailComponent() {
const emailEditorRef = useRef(null);

const onReady = (unlayer) => {
// Editor is ready. Optionally load a saved design here:
// unlayer.loadDesign(savedDesign);
};

const exportHtml = () => {
emailEditorRef.current?.editor.exportHtml((data) => {
const { design, html } = data;
console.log('HTML output:', html);
});
};

const saveDesign = () => {
emailEditorRef.current?.editor.saveDesign((design) => {
console.log('Design JSON:', design);
});
};

return (
<div>
<div>
<button onClick={exportHtml}>Export HTML</button>
<button onClick={saveDesign}>Save Design</button>
</div>
<EmailEditor ref={emailEditorRef} onReady={onReady} />
</div>
);
}

Render it from your app:

src/App.jsx
import EmailComponent from './EmailComponent';

export default function App() {
return <EmailComponent />;
}

onReady fires once the editor has fully loaded. Inside it, you can call any of the methods below — most commonly loadDesign to populate the editor with a saved template.

TypeScript

react-email-editor ships its own types. Pass the editor ref the right shape with EditorRef, and type the onReady handler with EmailEditorProps['onReady']:

src/EmailComponent.tsx
import React, { useRef } from 'react';
import EmailEditor, { EditorRef, EmailEditorProps } from 'react-email-editor';

export default function EmailComponent() {
const emailEditorRef = useRef<EditorRef>(null);

const onReady: EmailEditorProps['onReady'] = (unlayer) => {
// unlayer is fully typed here
};

return <EmailEditor ref={emailEditorRef} onReady={onReady} />;
}

Configuration

Pass editor configuration through the options prop. The shape matches the full unlayer.init configuration:

<EmailEditor
ref={emailEditorRef}
onReady={onReady}
options={{
projectId: 1234, // replace with your Unlayer Project ID
displayMode: 'email',
version: 'latest',
appearance: {
theme: 'modern_light',
},
features: {
ai: true,
textEditor: {
spellChecker: true,
},
},
}}
/>

Loading a saved design

const onReady = (unlayer) => {
const savedDesign = /* fetch from your backend */;
unlayer.loadDesign(savedDesign);
};

Methods

Available on emailEditorRef.current.editor:

MethodParamsDescription
loadDesignObject dataLoads a saved design JSON into the editor
saveDesignFunction callbackReturns the current design JSON via callback
exportHtmlFunction callbackReturns the rendered HTML and design JSON via callback

Props

NameTypeDescriptionDefault
styleObjectStyle for the editor container{}
minHeightStringMinimum height to initialize the editor with500px
onLoadFunctionCalled when the editor instance is created
onReadyFunctionCalled when the editor has finished loading
optionsObjectOptions passed to the Unlayer editor instance. See the configuration options for everything available.{}
toolsObjectConfiguration for built-in and custom tools{}
appearanceObjectConfiguration for appearance and theme{}

Example

A full working reference implementation lives in the react-email-editor demo.