UNPKG

@rooks/use-throttle

Version:
3 lines (2 loc) 693 B
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).useThrottle=t(e.React)}(this,(function(e){"use strict";return function(t,o=300){const[n,u]=e.useState(!0),r=e.useRef(void 0);if(!t||"function"!=typeof t)throw new Error("As a first argument, you need to pass a function to useThrottle hook.");const i=e.useCallback(((...e)=>{n&&(u(!1),t(...e))}),[n,t]);return e.useEffect((()=>{if(!n)return r.current=window.setTimeout((()=>{u(!0)}),o),()=>window.clearTimeout(r.current)}),[n,o]),[i,n]}})); //# sourceMappingURL=index.min.js.map