What is throttleit?
The throttleit package is a utility that allows you to throttle a function, meaning it limits the rate at which a function can fire. This is particularly useful for handling repetitive events that you want to control, such as window resizing, scrolling, or keypresses in a performant way.
Throttling function calls
This code sample demonstrates how to use throttleit to throttle a window resize event handler. The onResize function will not be called more than once every 200 milliseconds, no matter how often the resize event fires.
const throttle = require('throttleit');
function onResize(event) {
console.log('Window resized.');
}
window.addEventListener('resize', throttle(onResize, 200));