import { useRef } from 'react'; import { useSafeLayoutEffect } from './useSafeLayoutEffect'; interface ResultBox { v: T; } // eslint-disable-next-line @typescript-eslint/no-explicit-any export function useConstant(fn: () => T, deps: any[] = []): T { const ref = useRef>(); if (!ref.current) { ref.current = { v: fn() }; } useSafeLayoutEffect(() => { ref.current = { v: fn() }; }, deps); return ref.current.v as T; }