import { useEffect , useRef , useCallback } from 'react' ; import type { CallbackFunction } from '../types' ; param callback const useCallbackRef = < T extends CallbackFunction > ( callback ) : T => { const callbackRef = useRef ( callback ) ; useEffect ( ( ) => { callbackRef . current = callback ; } ) ; return useCallback ( ( ( ... args ) => { return callbackRef . current ?. ( ... args ) ; } ) as T , [ ] ) ; } ; export default useCallbackRef ;