import { useEffect, useState } from "react"

export const useDebounce = (value: string, delay: number = 400) => {
    const [debouncedSearch, setDebouncedSearch] = useState(value)

    useEffect(() => {
        const timer = setTimeout(() => setDebouncedSearch(value), delay)

        return () => clearTimeout(timer)
    }, [value, delay])
    
    return debouncedSearch    
}