UNPKG

@wix/design-system

Version:

@wix/design-system

26 lines (25 loc) 790 B
"use strict"; exports.__esModule = true; exports.useEventCallback = void 0; var _react = require("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. */ var useEventCallback = fn => { var ref = (0, _react.useRef)(fn); (0, _react.useLayoutEffect)(() => { ref.current = fn; }); return (0, _react.useMemo)(() => function () { var { current } = ref; return current(...arguments); }, []); }; exports.useEventCallback = useEventCallback; //# sourceMappingURL=useEventCallback.js.map