import { useRef } from "react"; import type * as React from "react"; export function useLazyRef any>( fn: F ): React.MutableRefObject> { let isSet = useRef(false); let ref = useRef(); if (!isSet.current) { isSet.current = true; ref.current = fn(); } return ref; }