Skip to main content

Modules

Save groups of rows as reusable content blocks that appear in the modules panel for drag-and-drop insertion.

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

function ModuleEditor() {
const editorRef = useRef<PexelizeEditorRef>(null);

const handleReady = async () => {
const editor = editorRef.current?.editor;

await editor?.setModules([
{
id: 'hero-banner',
name: 'Hero Banner',
category: 'Headers',
thumbnail: 'https://cdn.example.com/thumbs/hero.png',
design: heroDesignJson, // a saved DesignJson snippet
},
{
id: 'footer-standard',
name: 'Standard Footer',
category: 'Footers',
thumbnail: 'https://cdn.example.com/thumbs/footer.png',
design: footerDesignJson,
},
]);
};

return (
<PexelizeEditor
ref={editorRef}
editorKey="pk_your_key"
editorMode="email"
onReady={handleReady}
onModuleSave={async (module) => {
await fetch('/api/modules', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(module),
});
}}
/>
);
}
Module design JSON

A module's design property uses the same DesignJson format as exportJson(). Export a design, extract the rows you want, and save that subset as a module.

Synced modules

Synced modules stay linked to the source. When you update a synced module, all designs using it reflect the changes on next load:

await pexelize.setModules([
{
id: 'legal-footer',
name: 'Legal Footer',
category: 'Footers',
design: legalFooterJson,
synced: true, // Changes propagate to all designs using this module
},
]);
Synced module edits

Users cannot edit the content of a synced module inline. They must update the source module. Unsynced modules are fully editable after insertion.

Method reference

MethodReturnsDescription
setModules(modules)Promise<void>Set the available modules list
addModule(module)voidAppend a single module to the panel
removeModule(id)voidRemove a module by ID

Next steps