From 570e2d4496756c40136efdcae2b4c91209e422ee Mon Sep 17 00:00:00 2001 From: Eduard-Constantin Ibinceanu Date: Fri, 4 Oct 2024 16:56:53 +0000 Subject: [PATCH] Create debounce function --- apps/web/lib/utils.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/web/lib/utils.ts b/apps/web/lib/utils.ts index bd0c391d..01262daf 100644 --- a/apps/web/lib/utils.ts +++ b/apps/web/lib/utils.ts @@ -1,6 +1,17 @@ -import { clsx, type ClassValue } from "clsx" -import { twMerge } from "tailwind-merge" +import { clsx, type ClassValue } from 'clsx' +import { twMerge } from 'tailwind-merge' export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) } + +export function debounce void>( + func: T, + delay: number +): T { + let timeoutId: ReturnType + return function (this: any, ...args: Parameters) { + clearTimeout(timeoutId) + timeoutId = setTimeout(() => func.apply(this, args), delay) + } as T +}