UNPKG

@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
import { useEffect } from "react"; import { Debouncer } from "../Generics/Debouncer.js"; import { useController } from "./useController.js"; import { useUnmount } from "./useUnmount.js"; export const useDebouncer = (callback, wait) => { const debouncer = useController(new Debouncer(callback, wait)); useEffect(() => { debouncer.update(callback, wait); }, [debouncer, callback, wait]); useUnmount(() => { debouncer.cancel(); }); return debouncer; };