UNPKG

@wordpress/compose

Version:
17 lines (16 loc) 490 B
// packages/compose/src/hooks/use-throttle/index.js import { useMemoOne } from "use-memo-one"; import { useEffect } from "@wordpress/element"; import { throttle } from "../../utils/throttle"; function useThrottle(fn, wait, options) { const throttled = useMemoOne( () => throttle(fn, wait ?? 0, options), [fn, wait, options] ); useEffect(() => () => throttled.cancel(), [throttled]); return throttled; } export { useThrottle as default }; //# sourceMappingURL=index.js.map