A TypeScript debounce function that can be used to limit the frequency of function calls.
import { debounce } from '@garmingo/debounce';
const myFunction = () => {
console.log('Debounced function called');
};
const debouncedFunction = debounce(myFunction, 500); // Set the delay time in milliseconds
// Call debouncedFunction multiple times quickly
debouncedFunction();
debouncedFunction();
debouncedFunction();
// Only one actual call to myFunction will be made after 500ms
func
: The original function you want to debounce.delay
: The delay time in milliseconds.
- Create .npmrc file with the following content:
@garmingo:registry=https://npm.pkg.github.com
- Install using npm
npm i @garmingo/debounce