Skip to content

Commit

Permalink
enhancement: Add Live Preview Support to Payload
Browse files Browse the repository at this point in the history
  • Loading branch information
m453h committed Jul 15, 2024
1 parent aa387c5 commit 77b18ab
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions apps/roboshield/src/pages/[[...slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ import { getPageServerSideProps } from "@/roboshield/lib/data";
import BlockRenderer from "@/roboshield/components/BlockRenderer";
import { PageProps } from "@/roboshield/lib/data";
import { GetServerSidePropsContext } from "next";
import { useLivePreview } from "@payloadcms/live-preview-react";

export default function Page({ blocks }: PageProps) {
return <BlockRenderer blocks={blocks} />;
}
const Page: React.FC<PageProps> = (initialPage) => {
const { data } = useLivePreview({
serverURL: process.env.NEXT_PUBLIC_APP_URL || "",
depth: 2,
initialData: initialPage,
});

return <BlockRenderer blocks={data?.blocks} />;
};

export default Page;

export async function getServerSideProps(context: GetServerSidePropsContext) {
const { props } = await getPageServerSideProps(context);
Expand Down

0 comments on commit 77b18ab

Please sign in to comment.