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