let timeoutId: NodeJS.Timeout | null = null;
const debounce = (func: Function, delay = 1000): void => {
if (timeoutId != null) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
func();
timeoutId = null;
}, delay);
};
See the Pen debounce by Yoshiharu (@yoshiharu2580) on CodePen.