admin/hooks/useDeferredClientMount.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

27 lines
648 B
TypeScript

'use client'
import { useEffect, useState } from 'react'
/** Default delay — keeps deferred chrome out of the LCP window on cold loads. */
export const DEFERRED_CHROME_DELAY_MS = 4000
/**
* Returns true after `delayMs` so non-critical client UI (PWA banner, etc.) mounts
* after the first paint / LCP candidates.
*/
export function useDeferredClientMount(delayMs = DEFERRED_CHROME_DELAY_MS) {
const [ready, setReady] = useState(false)
useEffect(() => {
const timeoutId = window.setTimeout(() => {
setReady(true)
}, delayMs)
return () => {
window.clearTimeout(timeoutId)
}
}, [delayMs])
return ready
}