import { useRef } from 'react'; type ResultBox = { v: T }; export function useConstant(fn: () => T): T { const ref = useRef>(null); if (!ref.current) { ref.current = { v: fn() }; } return ref.current.v; } export function useConstantCallback unknown>( callback: T ) { return useConstant(() => callback); }