UNPKG

@wordpress/compose

Version:
37 lines (30 loc) 957 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = useThrottle; var _lodash = require("lodash"); var _useMemoOne = require("use-memo-one"); var _element = require("@wordpress/element"); /** * External dependencies */ /** * WordPress dependencies */ /** * Throttles a function with Lodash's `throttle`. A new throttled function will * be returned and any scheduled calls cancelled if any of the arguments change, * including the function to throttle, so please wrap functions created on * render in components in `useCallback`. * * @param {...any} args Arguments passed to Lodash's `throttle`. * * @return {Function} Throttled function. */ function useThrottle(...args) { const throttled = (0, _useMemoOne.useMemoOne)(() => (0, _lodash.throttle)(...args), args); (0, _element.useEffect)(() => () => throttled.cancel(), [throttled]); return throttled; } //# sourceMappingURL=index.js.map