Understanding preview mode in Next.js with Sanity
usePreviewhook via preview components. Creating preview components was impractical so I've taken a very different approach which seems to be working well.
If you’re querying for a blog post that has a referenced category — you won’t get the draft version of that category.
Here’s where my current experiment is. It’s using remix but you could adapt to Next.
It’s a way to render your components as normal, unless the site is in preview mode where it would instead run that render function.
usePreviewhook inside my existing RQ hooks (as that's where my groq queries live - I really don't want to export them too) - though conditionally doing so might be tricky 😞
• Like all things with great power comes great responsibility. You’re responsible for implementing adequate protection against leaking thetokenin your js bundle, or preventing the/api/preview?secret=${secret}from being easily guessable.
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.