JSFiddle - React, Tailwind, and code Playground
JavaScript
class Debouncer {
constructor(wait) {
this.wait = wait;
this.timeout = null;
}
schedule(func) {
console.log(`args to schedule: ${args}`);
return () => {
if (this.timeout) {
clearTimeout(this.timeout);
}
this.timeout = setTimeout(() => {
func();
this.timeout = null; // Clear the timeout ID after execution
}, this.wait);
};
}
}
export default Debouncer;