import { ForwardedRef, useEffect, useRef } from "react"; /** * Taken over from https://github.com/facebook/react/issues/24722 * * Probably not the best name: * * * @param ref * @param initialValue */ export const useForwardRef = (ref: ForwardedRef, initialValue: any = null) => { const targetRef = useRef(initialValue); useEffect(() => { if (!ref) return; if (typeof ref === "function") { ref(targetRef.current); } else { ref.current = targetRef.current; } }, [ref]); return targetRef; };