Download spectrum/src/hooks/useDebounce.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 474 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/src/hooks/useDebounce.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/src/hooks/useDebounce.js
-
curl -L -o useDebounce.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/src/hooks/useDebounce.js
474 Bytes
| // @flow | |
| import { useState, useEffect } from 'react'; | |
| // @see https://dev.to/gabe_ragland/debouncing-with-react-hooks-jci | |
| function useDebounce(value: string, delay: number) { | |
| const [debouncedValue, setDebouncedValue] = useState(value); | |
| useEffect(() => { | |
| const handler = setTimeout(() => { | |
| setDebouncedValue(value); | |
| }, delay); | |
| return () => { | |
| clearTimeout(handler); | |
| }; | |
| }, [value]); | |
| return debouncedValue; | |
| } | |
| export default useDebounce; | |