Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
1 line
5.0 KiB
Plaintext
1 line
5.0 KiB
Plaintext
{"version":3,"file":"useDelayedRender.js","names":["c","_c","React","useDelay","useDelayedRender","t0","$","delayBeforeShow","inTimeout","minShowTime","outTimeout","show","totalMountTime","hasDelayed","triggerDelay","isMounted","setIsMounted","useState","isUnmounting","setIsUnmounting","onMountTimestampRef","useRef","unmountTimeoutRef","undefined","t1","current","setTimeout","unmount","t2","t3","shouldMount","shouldUnmount","Date","now","totalTimeMounted","remainingTime","clearTimeout","Math","max","useEffect","t4","triggerDelayedRender"],"sources":["../../src/hooks/useDelayedRender.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport { useDelay } from './useDelay.js'\n\ntype DelayedRenderProps = {\n /** Time in ms to wait before \"mounting\" the component. */\n delayBeforeShow: number\n /** Time in ms for the \"enter\" phase of the transition, after delay completes. */\n inTimeout: number\n /** Min time in ms for the \"entered\" phase of the transition. */\n minShowTime: number\n /** Time in ms for the exit phase of the transition. */\n outTimeout: number\n /** `true` starts the mount process.\n * `false` starts the unmount process.\n * */\n show: boolean\n}\ntype useDelayedRenderT = (props: DelayedRenderProps) => {\n /** `true` if the component has mounted after the timeout. */\n isMounted: boolean\n /** `true` if the component is unmounting. */\n isUnmounting: boolean\n /** Call this function to trigger the timeout delay before rendering. */\n triggerDelayedRender: () => void\n}\nexport const useDelayedRender: useDelayedRenderT = ({\n delayBeforeShow,\n inTimeout,\n minShowTime,\n outTimeout,\n show,\n}) => {\n const totalMountTime = inTimeout + minShowTime + outTimeout\n const [hasDelayed, triggerDelay] = useDelay(delayBeforeShow)\n const [isMounted, setIsMounted] = React.useState(false)\n const [isUnmounting, setIsUnmounting] = React.useState(false)\n const onMountTimestampRef = React.useRef(0)\n const unmountTimeoutRef: React.RefObject<NodeJS.Timeout | undefined> = React.useRef(undefined)\n\n const unmount = React.useCallback(() => {\n setIsUnmounting(true)\n unmountTimeoutRef.current = setTimeout(() => {\n setIsMounted(false)\n setIsUnmounting(false)\n }, outTimeout)\n }, [setIsUnmounting, outTimeout])\n\n React.useEffect(() => {\n const shouldMount = hasDelayed && !isMounted && show\n const shouldUnmount = isMounted && !show\n\n if (shouldMount) {\n onMountTimestampRef.current = Date.now()\n setIsMounted(true)\n } else if (shouldUnmount) {\n const totalTimeMounted = Date.now() - onMountTimestampRef.current\n const remainingTime = totalMountTime - totalTimeMounted\n clearTimeout(unmountTimeoutRef.current)\n unmountTimeoutRef.current = setTimeout(unmount, Math.max(0, remainingTime))\n }\n }, [isMounted, show, unmount, totalMountTime, hasDelayed])\n\n return {\n isMounted,\n isUnmounting,\n triggerDelayedRender: triggerDelay,\n }\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AACA,YAAYC,KAAA,MAAW;AAEvB,SAASC,QAAQ,QAAQ;AAwBzB,OAAO,MAAMC,gBAAA,GAAsCC,EAAA;EAAA,MAAAC,CAAA,GAAAL,EAAA;EAAC;IAAAM,eAAA;IAAAC,SAAA;IAAAC,WAAA;IAAAC,UAAA;IAAAC;EAAA,IAAAN,EAMnD;EACC,MAAAO,cAAA,GAAuBJ,SAAA,GAAYC,WAAA,GAAcC,UAAA;EACjD,OAAAG,UAAA,EAAAC,YAAA,IAAmCX,QAAA,CAASI,eAAA;EAC5C,OAAAQ,SAAA,EAAAC,YAAA,IAAkCd,KAAA,CAAAe,QAAA,MAAe;EACjD,OAAAC,YAAA,EAAAC,eAAA,IAAwCjB,KAAA,CAAAe,QAAA,MAAe;EACvD,MAAAG,mBAAA,GAA4BlB,KAAA,CAAAmB,MAAA,EAAa;EACzC,MAAAC,iBAAA,GAA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