/** * // https://dev.to/gabe_ragland/debouncing-with-react-hooks-jci * const [value, setValue] = useState() * const debouncedValue = useDebounce(value, 800) */ function useDebounce(nextValue, delay) { const [currentValue, setCurrentValue] = useState(nextValue); useEffect(() => { const handler = setTimeout(() => setCurrentValue(nextValue), delay); return () => clearTimeout(handler); }, [nextValue, delay]); return currentValue; }