/* eslint-disable react-hooks/exhaustive-deps */ import type React from 'react'; import { useCallback, type Ref } from 'react'; type PossibleRef = Ref | undefined; export function assignRef(ref: PossibleRef, value: T) { if (typeof ref === 'function') { ref(value); } else if (typeof ref === 'object' && ref !== null && 'current' in ref) { (ref as React.MutableRefObject).current = value; } } export function mergeRefs(...refs: PossibleRef[]) { return (node: T | null) => { refs.forEach((ref) => assignRef(ref, node)); }; } export function useMergedRef(...refs: PossibleRef[]) { return useCallback(mergeRefs(...refs), refs); }