Create debounce function

This commit is contained in:
Eduard-Constantin Ibinceanu 2024-10-04 16:56:53 +00:00
parent 54a28637e5
commit 570e2d4496

View file

@ -1,6 +1,17 @@
import { clsx, type ClassValue } from "clsx" import { clsx, type ClassValue } from 'clsx'
import { twMerge } from "tailwind-merge" import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) { export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs)) return twMerge(clsx(inputs))
} }
export function debounce<T extends (...args: any[]) => void>(
func: T,
delay: number
): T {
let timeoutId: ReturnType<typeof setTimeout>
return function (this: any, ...args: Parameters<T>) {
clearTimeout(timeoutId)
timeoutId = setTimeout(() => func.apply(this, args), delay)
} as T
}