@darshanahire/use-debounce
v1.0.1
Published
A lightweight utility function to debounce any callback in JavaScript or Node.js. Useful for optimizing performance by limiting the rate at which a function is executed.
Readme
🕒 use-debounce
A lightweight utility function to debounce any callback in JavaScript or Node.js. Useful for optimizing performance by limiting the rate at which a function is executed.
📦 Installation
npm install use-debounce🚀 Usage
const debounce = require("use-debounce");
const log = () => {
console.log("Debounced call");
};
const debouncedLog = debounce(log, 1000);
// Simulate rapid calls
debouncedLog();
debouncedLog();
debouncedLog(); // Only this one will execute after 1 second🔧 API
debounce(callback, delay)
callback– the function you want to debouncedelay– the delay in milliseconds
Returns a debounced version of your callback.
🛠️ Example Use Cases
- Debouncing user input in CLI or UI
- Limiting API calls
- Improving performance on scroll, resize, or typing events
📄 License
MIT
