@figliolia/react-hooks
Version:
A small collection of simple React Hooks you're probably rewriting on a regular basis
15 lines (14 loc) • 490 B
JavaScript
import { useEffect } from "react";
import { Throttler } from "../Generics/Throttler.js";
import { useController } from "./useController.js";
import { useUnmount } from "./useUnmount.js";
export const useThrottler = (callback, wait) => {
const throttler = useController(new Throttler(callback, wait));
useEffect(() => {
throttler.update(callback, wait);
}, [throttler, callback, wait]);
useUnmount(() => {
throttler.cancel();
});
return throttler;
};