mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-26 23:01:34 +00:00
d7b997e86c
Move useDebounce hook GitOrigin-RevId: f047e279ca1694fc4fa68aa098d6608edefd20fe
17 lines
380 B
JavaScript
17 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
|
|
}
|