UNPKG

@gdjiami/hooks

Version:

react hooks for mygzb.com

21 lines (17 loc) 405 B
import { useEffect } from 'react'; function useDebounce(fn, ms, args) { if (ms === void 0) { ms = 1000; } if (args === void 0) { args = []; } useEffect(function () { var handle = setTimeout(fn.bind.apply(fn, [null].concat(args)), ms); return function () { // if args change then clear timeout clearTimeout(handle); }; }, args); } export default useDebounce;