DEV Community

Discussion on: How to make a custom Debounce hook in react js

Collapse
 
pratikdungarani profile image
pratikdungarani • Edited

export function useDebouncedValue(value, wait) {
const [debouncedValue, setDebouncedValue] = useState(value);

  useEffect(() => {
     const id = setTimeout(() => setDebouncedValue(value), wait);
     return () => clearTimeout(id);
  }, [value]);
Enter fullscreen mode Exit fullscreen mode

return debouncedValue;

}