Created
January 15, 2020 09:15
-
-
Save davalapar/ecdc74913d4c5b10a6085b0494442dd7 to your computer and use it in GitHub Desktop.
Revisions
-
davalapar created this gist
Jan 15, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ /** * // 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; }