Skip to content
Snippets Groups Projects
Commit 24c2616a authored by Matt Kirby's avatar Matt Kirby
Browse files

Added debounce hook

parent 7d375309
No related branches found
No related tags found
1 merge request!18Fe search and friends (sorry in advance)
import { useEffect, useState } from 'react'
function useDebounce<T>(value: T, delay?: number): T {
const [debouncedValue, setDebouncedValue] = useState<T>(value)
useEffect(() => {
const timer = setTimeout(() => setDebouncedValue(value), delay || 500)
return () => {
clearTimeout(timer)
}
}, [value, delay])
return debouncedValue
}
export default useDebounce
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment