14 lines
326 B
TypeScript
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
|
||
|
}, [])
|
||
|
}
|