import { useRef } from "react"; export function useConstant(init: () => T): T { const initialized = useRef(false); const ref = useRef(); if (!initialized.current) { initialized.current = true; ref.current = init(); } return ref.current; }