ziko
Version:
a versatile javaScript framework offering a rich set of UI components, advanced mathematical utilities, reactivity, animations, client side routing and graphics capabilities
17 lines • 389 B
JavaScript
const useDebounce=(fn,delay=1000)=>{
let id;
return(...args)=>id?clearTimeout(id):setTimeout(()=>fn(...args),delay)
}
const useThrottle=(fn,delay)=>{
let lastTime=0;
return (...args)=>{
const now=new Date().getTime()
if(now-lastTime<delay)return;
lastTime=now;
fn(...args);
}
}
export{
useDebounce,
useThrottle
}