Preview Data

The previewData function allows you to read data from Preview Mode inside a server component.

app/page.js
import { previewData } from 'next/headers';

export default function Page() {
  const data = previewData();
  const isPreviewMode = !!data && data.key === process.env.PREVIEW_SECRET;

  return isPreviewMode ? <h1>Preview Mode</h1> : <h1>Not in Preview Mode</h1>;
}