import { useCallback , useEffect , useRef } from "react" ; /**
 * This hook allows you to intercept a RefCallback and receive the element in
 * another function as well.
 */ const useMergedCallbackRef = ( ... callbacks ) => { const callbacksRegistry = useRef < Function [ ] > ( callbacks ) ; useEffect ( ( ) => { callbacksRegistry . current = callbacks ; } , [ ... callbacks ] ) ; return useCallback ( ( element ) => { callbacksRegistry . current . forEach ( ( callback ) => callback ( element ) ) ; } , [ ] ) ; } ; export default useMergedCallbackRef ;