mirror of
https://github.com/hanzo-io/team.git
synced 2026-10-30 18:56:23 +00:00
17 lines
425 B
TypeScript
17 lines
425 B
TypeScript
import { useState, useEffect } from 'react'
|
|
|
|
export const useDebounce = <T = any>(value: T, delay: number = 200): T => {
|
|
const [debouncedValue, setDebouncedValue] = useState(value)
|
|
|
|
useEffect(() => {
|
|
const handler = setTimeout(() => {
|
|
setDebouncedValue(value)
|
|
}, delay)
|
|
|
|
return () => {
|
|
clearTimeout(handler)
|
|
}
|
|
}, [value, delay])
|
|
|
|
return debouncedValue
|
|
} |