export function useTimeout(callback: () => void, delay: number) {
const savedCallback = useRef(callback)
useEffect(() => {
savedCallback.current = callback
}, [callback])
useEffect(() => {
const id = setTimeout(() => {
savedCallback.current()
}, delay)
return () => {
clearTimeout(id)
}
}, [delay])
}