UNPKG

@d3vtool/hooks

Version:

Collection of custom React hooks to simplify tasks in your React projects.

2 lines (1 loc) 784 B
"use strict";var i=function(l,t){var n=typeof Symbol=="function"&&l[Symbol.iterator];if(!n)return l;var e=n.call(l),a,r=[],u;try{for(;(t===void 0||t-- >0)&&!(a=e.next()).done;)r.push(a.value)}catch(o){u={error:o}}finally{try{a&&!a.done&&(n=e.return)&&n.call(e)}finally{if(u)throw u.error}}return r},c=function(l,t,n){if(n||arguments.length===2)for(var e=0,a=t.length,r;e<a;e++)(r||!(e in t))&&(r||(r=Array.prototype.slice.call(t,0,e)),r[e]=t[e]);return l.concat(r||Array.prototype.slice.call(t))};import{useCallback as f,useRef as s}from"react";export function useDebounce(l,t){var n=s(null),e=f(function(){for(var a=[],r=0;r<arguments.length;r++)a[r]=arguments[r];n.current&&clearTimeout(n.current),n.current=setTimeout(function(){t.apply(void 0,c([],i(a),!1))},l)},[l,t]);return e}