EcoTracker-II / frontend /src /utils /debounce.js
Akash-Dragon's picture
feat: build React/Vite frontend client with TailwindCSS
687ebbb
Raw
History Blame Contribute Delete
481 Bytes
/**
* Debounce utility
* Delays invoking `fn` until after `wait` ms have elapsed since the last call.
*
* @param {Function} fn - function to debounce
* @param {number} wait - delay in milliseconds (default 300)
* @returns {Function} debounced function
*/
export function debounce(fn, wait = 300) {
let timeoutId = null;
return function debounced(...args) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
fn.apply(this, args);
}, wait);
};
}