Files
supabase/apps/www/hooks/useDraftMode.ts
Francesco Sansalvadore 2feda5ee19 cms www blog (#38045)
* show cms blog posts in www
* remove contentlayer from www
* outputFileTracingExcludes
* update remotePatterns
* fetch cms posts server-side with revalidation
* add cms env vars to turbo.json
* add www env vars to turbo.json
* include cms posts in www sitemap
* add migration to remove image from cms post
* update cms meta image mapping in www
2025-09-03 14:49:28 +02:00

22 lines
587 B
TypeScript

'use client'
import { useEffect, useState } from 'react'
/**
* Hook to detect if the user is in Next.js Draft Mode
* Checks for the __prerender_bypass cookie that Next.js sets when draft mode is enabled
*/
export function useDraftMode() {
const [isDraftMode, setIsDraftMode] = useState(false)
useEffect(() => {
// Check if we're in the browser and if the draft mode cookie exists
if (typeof window !== 'undefined') {
const hasDraftCookie = document.cookie.includes('__prerender_bypass')
setIsDraftMode(hasDraftCookie)
}
}, [])
return isDraftMode
}