learnhouse/apps/web/lib/utils.ts
Eduard-Constantin Ibinceanu 570e2d4496 Create debounce function
2024-10-04 16:56:53 +00:00

17 lines
469 B
TypeScript

import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) {
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
}