all repos — caroster @ a5cf0e5ec409bf5e3c76c95bccb10adaad3758e2

[Octree] Group carpool to your event https://caroster.io

app/src/hooks/useDebounce.js (view raw)

 1import { useState, useEffect } from "react";
 2
 3// https://github.com/xnimorz/use-debounce
 4function useDebounce(value, delay) {
 5  const [debouncedValue, setDebouncedValue] = useState(value);
 6
 7  useEffect(() => {
 8    const handler = setTimeout(() => {
 9      setDebouncedValue(value);
10    }, delay);
11
12    return () => {
13      clearTimeout(handler);
14    };
15  }, [value, delay]);
16
17  return debouncedValue;
18}
19
20export default useDebounce;