Download react-use/src/useHarmonicIntervalFn.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 584 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/src/useHarmonicIntervalFn.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/src/useHarmonicIntervalFn.ts
-
curl -L -o useHarmonicIntervalFn.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/src/useHarmonicIntervalFn.ts
584 Bytes
| import { useEffect, useRef } from 'react'; | |
| import { clearHarmonicInterval, setHarmonicInterval } from 'set-harmonic-interval'; | |
| const useHarmonicIntervalFn = (fn: Function, delay: number | null = 0) => { | |
| const latestCallback = useRef<Function>(() => {}); | |
| useEffect(() => { | |
| latestCallback.current = fn; | |
| }); | |
| useEffect(() => { | |
| if (delay !== null) { | |
| const interval = setHarmonicInterval(() => latestCallback.current(), delay); | |
| return () => clearHarmonicInterval(interval); | |
| } | |
| return undefined; | |
| }, [delay]); | |
| }; | |
| export default useHarmonicIntervalFn; | |