@figliolia/react-hooks
Version:
A small collection of simple React Hooks you're probably rewriting on a regular basis
19 lines (18 loc) • 691 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useThrottler = void 0;
const react_1 = require("react");
const Throttler_1 = require("../Generics/Throttler");
const useController_1 = require("./useController");
const useUnmount_1 = require("./useUnmount");
const useThrottler = (callback, wait) => {
const throttler = (0, useController_1.useController)(new Throttler_1.Throttler(callback, wait));
(0, react_1.useEffect)(() => {
throttler.update(callback, wait);
}, [throttler, callback, wait]);
(0, useUnmount_1.useUnmount)(() => {
throttler.cancel();
});
return throttler;
};
exports.useThrottler = useThrottler;