I am facing an issue with checking if preview mode is activated on my website.
While following a YouTube tutorial, I realized that the instructions may be outdated with the latest NextJS update.
This was the code snippet I was originally working with to determine the status of preview mode:
import groq from 'groq';
import { previewData } from "next/headers"
const query = groq`
*[_type=='post']{
...,
author->,
categories[]->,
} | order(_createAt desc)`;
export default function Home() {
if (previewData()) {
return (
<div><h1>In preview mode</h1></div>
)
}
return (
<div><h1>Not in preview mode</h1></div>
)
}
However, it seems that previewData()
is no longer exported by next/headers
, leaving me unsure of how to proceed further.
I attempted using getServerSideProps but discovered that it cannot be utilized in the app directory within NextJs 13.
Even after consulting the Sanity documentation for guidance, I have yet to find a solution to resolve this issue.