export type IRef < T extends HTMLElement = HTMLElement > = IRefObject < T > | IRefCallback < T > ; export interface IRefObject < T extends HTMLElement = HTMLElement > { current : T | null ; } export function isRefObject < T extends HTMLElement > ( value ) { return value != null && typeof value !== "function" ; } export type IRefCallback < T extends HTMLElement = HTMLElement > = ( ref : T | null ) => any ; export function isRefCallback < T extends HTMLElement > ( value ) { return typeof value === "function" ; } /**
 * Assign the given ref to a target, either a React ref object or a callback which takes the ref as its first argument.
 */ export function setRef < T extends HTMLElement > ( refTarget , ref ) { if ( isRefObject < T > ( refTarget ) ) { refTarget . current = ref ; } else if ( isRefCallback ( refTarget ) ) { refTarget ( ref ) ; } } deprecated export function combineRefs < T extends HTMLElement > ( ref1 , ref2 ) { return mergeRefs ( ref1 , ref2 ) ; } /**
 * Utility for merging refs into one singular callback ref.
 * If using in a functional component, would recomend using `useMemo` to preserve function identity.
 */ export function mergeRefs < T extends HTMLElement > ( ... refs ) { return value => { refs . forEach ( ref => { setRef ( ref , value ) ; } ) ; } ; } export function getRef < T extends HTMLElement > ( ref ) { if ( ref === null ) { return null ; } return ( ref as IRefObject < T > ) . current ?? ( ref as T ) ; } /**
 * Creates a ref handler which assigns the ref returned by React for a mounted component to a field on the target object.
 * The target object is usually a component class.
 *
 * If provided, it will also update the given `refProp` with the value of the ref.
 */ export function refHandler < T extends HTMLElement , K extends string > ( refTargetParent , refTargetKey , refProp ? ) { return ( ref ) => { refTargetParent [ refTargetKey ] = ref ; setRef ( refProp , ref ) ; } ; }