import type { MutableRefObject, RefCallback } from 'react'; type RefType = MutableRefObject | RefCallback | null; export const shareRef = (refA: RefType, refB: RefType): RefCallback => instance => { if (typeof refA === 'function') { refA(instance); } else if (refA && 'current' in refA) { (refA as MutableRefObject).current = instance as T; // Use type assertion to tell TypeScript the type } if (typeof refB === 'function') { refB(instance); } else if (refB && 'current' in refB) { (refB as MutableRefObject).current = instance as T; // Use type assertion to tell TypeScript the type } };