// https://github.com/Volune/use-event-callback/blob/master/src/index.ts import { useLayoutEffect, useMemo, useRef } from 'react' type Fn = (...args: ARGS) => R const useEventCallback = (fn: Fn): Fn => { const ref = useRef>(fn) useLayoutEffect(() => { ref.current = fn }) return useMemo( () => (...args: A): R => { const { current } = ref return current(...args) }, [] ) } export default useEventCallback