import { ForwardedRef, useEffect, useRef } from 'react'; // Types import { Nullable } from '../globals/types'; const useForwardRef = ( ref: ForwardedRef, initialValue: Nullable = null ) => { const targetRef = useRef(initialValue); useEffect(() => { if (!ref) return; if (typeof ref === 'function') { ref(targetRef.current); } else { ref.current = targetRef.current; } }, [ref]); return targetRef; }; export { useForwardRef };