@webfactoryde/debounce
v1.0.0
Published
A JS utility that delays the execution of a callback function until after a defined period of inactivity, preventing multiple rapid calls.
Keywords
Readme
debounce Utility
The debounce utility is a simple JavaScript function that limits the rate at which a particular callback function can be executed. It ensures that a function is only called after a specified delay period has passed since the last time it was invoked. This is particularly useful for optimizing performance in scenarios like handling user input events, where rapid calls can lead to unnecessary processing.
Installation
npm install @webfactoryde/debounceUsage
Import the debounce function in your module(s) and pass a callback that you want to rate-limit:
// your module
import debounce from '@webfactoryde/debounce';
function coolFunction() {
// do cool stuff
}
window.addEventListener('resize', debounce(coolFunction, 200));