import { useCallback , useRef } from 'react' ; import useEnhancedEffect from './useEnhancedEffect' ; export default function useEventCallback < Args extends unknown [ ] , Return > ( fn , dependencies ) { const ref = useRef ( fn ) ; useEnhancedEffect ( ( ) => { ref . current = fn ; } , [ fn , ... dependencies ] ) ; return useCallback ( ( ... args ) => ( 0 , ref . current ! ) ( ... args ) , [ ] ) ; }