import { useRef } from "react"; type ResultBox = { v: T }; export function useConstant(fn: () => T): T { const ref = useRef>(); if (!ref.current) { ref.current = { v: fn() }; } return ref.current?.v; }