import React from 'react'; type CallbackRef = (ref: T | null) => void; type Ref = React.MutableRefObject | CallbackRef; const toFnRef = (ref?: Ref | null) => !ref || typeof ref === 'function' ? ref : (value: T | null) => { ref.current = value; }; export default function mergeRefs( refA?: Ref | null, refB?: Ref | null ): React.RefCallback { const a = toFnRef(refA); const b = toFnRef(refB); return (value: T | null) => { if (typeof a === 'function') a(value); if (typeof b === 'function') b(value); }; }