/**
 * File: useDebounce.ts
 * Purpose: This file contains a custom hook for debouncing function calls.
 *          It prevents multiple function calls from being made in a short period of time.
*/

import { useRef } from 'react'

export const useDebounce = (callback: (...args: any[]) => void, delay: number) => {
    const timeoutRef = useRef<any>(null)

    return (...args: any[]) => {
        if (timeoutRef.current) {
            clearTimeout(timeoutRef.current)
        }
        timeoutRef.current = setTimeout(() => {
            callback(...args)
        }, delay)
    }
}
