UNPKG

hooks-me

Version:

<div align="center"> <h1>hooks-me</h1> <div>React useful hooks.</div>

24 lines (23 loc) 919 B
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import { useEffect } from "react"; import useTimeout from "./useTimeout"; /** * * @param callback Method to call * @param delay Delay in ms * @param dependencies If present, effect will only activate if the values in the list change. */ var useDebounce = function (callback, delay, dependencies) { var _a = useTimeout(callback, delay), reset = _a.reset, clear = _a.clear; useEffect(reset, __spreadArray(__spreadArray([], (dependencies || []), true), [reset], false)); useEffect(clear, []); }; export default useDebounce;