manifold/web/hooks/use-time-since-first-render.ts
2022-04-21 01:00:08 -05:00

14 lines
326 B
TypeScript

import { useCallback, useEffect, useRef } from 'react'
export function useTimeSinceFirstRender() {
const startTimeRef = useRef(0)
useEffect(() => {
startTimeRef.current = Date.now()
}, [])
return useCallback(() => {
if (!startTimeRef.current) return 0
return Date.now() - startTimeRef.current
}, [])
}