UNPKG

@wix/design-system

Version:

@wix/design-system

19 lines 682 B
import { useLayoutEffect, useMemo, useRef } from 'react'; /** * A hook that returns a stable callback that always has the latest version of the provided function. * Taken from https://github.com/Volune/use-event-callback/blob/master/src/index.ts * * @param {Fn<ARGS, R>} fn - The callback function. * @returns {Fn<ARGS, R>} A stable version of the provided callback function. */ export const useEventCallback = (fn) => { const ref = useRef(fn); useLayoutEffect(() => { ref.current = fn; }); return useMemo(() => (...args) => { const { current } = ref; return current(...args); }, []); }; //# sourceMappingURL=useEventCallback.js.map