Generate experiences with Puck AI
Read docs
EditorData & renderingSave and render pages

Save and render pages

Puck edits a Data object. Store it anywhere that holds JSON. Render it with <Render>.

Save the data

onPublish runs when the user clicks “Publish”. Send the data to your server:

import { Puck } from "@puckeditor/core";
 
const saveData = () => {}; // Save to your backend
 
export function Editor({ path, data }) {
  return (
    <Puck
      config={config}
      data={data}
      onPublish={async (newData) => {
        await saveData(path, newData);
      }}
    />
  );
}

Don’t have a backend? Try Puck Pages to store your pages in Puck Cloud, with built-in drafts, versions and data migrations.

Load the data

To continue editing, pass the saved data to <Puck>:

import { Puck } from "@puckeditor/core";
 
const getPage = () => {}; // Read from your database
const data = await getPage(path);
 
export function Editor() {
  return <Puck config={config} data={data} />;
}

Render the page

Render the saved data with <Render> and the same config:

import { Render } from "@puckeditor/core";
 
const getPage = () => {}; // Read from your database
const data = await getPage(path);
 
export function Page() {
  return <Render config={config} data={data} />;
}

If your components use resolveData, run resolveAllData() first. The page then renders with the resolved props:

import { Render, resolveAllData } from "@puckeditor/core";
 
const getPage = () => {}; // Read from your database
const data = await getPage(path);
const resolvedData = await resolveAllData(data, config);
 
export function Page() {
  return <Render config={config} data={resolvedData} />;
}

Further reading