mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-26 10:43:18 +00:00
18 lines
380 B
JavaScript
18 lines
380 B
JavaScript
|
import { useEffect, useState } from 'react'
|
||
|
|
||
|
export default function useDebounce(value, delay = 0) {
|
||
|
const [debouncedValue, setDebouncedValue] = useState(value)
|
||
|
|
||
|
useEffect(() => {
|
||
|
const timer = window.setTimeout(() => {
|
||
|
setDebouncedValue(value)
|
||
|
}, delay)
|
||
|
|
||
|
return () => {
|
||
|
window.clearTimeout(timer)
|
||
|
}
|
||
|
}, [value, delay])
|
||
|
|
||
|
return debouncedValue
|
||
|
}
|