Skip to main content

Multiple Editors

Create multiple independent editor instances on a single page, each with its own configuration, design, and lifecycle.

import { useRef } from 'react';
import { PexelizeEditor, PexelizeEditorRef } from '@pexelize/react-editor';

function MultiEditorPage() {
const headerEditor = useRef<PexelizeEditorRef>(null);
const bodyEditor = useRef<PexelizeEditorRef>(null);

const saveAll = async () => {
const [headerJson, bodyJson] = await Promise.all([
headerEditor.current?.editor?.exportJson(),
bodyEditor.current?.editor?.exportJson(),
]);
await fetch('/api/designs/save', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ header: headerJson, body: bodyJson }),
});
};

return (
<>
<h2>Header Section</h2>
<PexelizeEditor
ref={headerEditor}
editorKey="pk_your_key"
editorMode="email"
style={{ height: '300px' }}
/>

<h2>Body Section</h2>
<PexelizeEditor
ref={bodyEditor}
editorKey="pk_your_key"
editorMode="email"
style={{ height: '500px' }}
/>

<button onClick={saveAll}>Save All</button>
</>
);
}
Same editorKey supported

Multiple editor instances can share the same editorKey. Each instance runs in its own iframe with fully isolated state (design data, undo/redo, event listeners). The only requirement is a unique containerId per instance, which framework wrappers generate automatically.

Unique containerId required

Each editor instance must have its own DOM container element with a distinct id. Reusing the same container ID will cause the second editor to fail silently. Framework wrappers (React, Vue, Angular) handle this automatically.

Lifecycle management

Destroy editor instances when they are no longer needed to free memory:

// Vanilla JS
headerInstance.destroy();
bodyInstance.destroy();

// React — handled automatically on unmount
// Vue — handled automatically on unmount
// Angular — handled automatically on component destroy
Framework wrappers handle cleanup

React, Vue, and Angular wrappers automatically destroy the editor instance when the component unmounts. You only need to call destroy() manually with the Vanilla JS API.

Method reference

MethodReturnsDescription
createEditor(config)PexelizeInstanceCreate a new independent editor instance
destroy()voidDestroy an editor instance and free resources

Next steps