MCPcopy Create free account
hub / github.com/dabbott/react-native-express / useInterval

Function useInterval

examples/files/hooks/useInterval.js:4–21  ·  view source on GitHub ↗
(callback, delay)

Source from the content-addressed store, hash-verified

2import { Text } from 'react-native'
3
4function useInterval(callback, delay) {
5 const savedCallback = useRef()
6
7 // Remember the latest callback.
8 useEffect(() => {
9 savedCallback.current = callback
10 }, [callback])
11
12 // Set up the interval.
13 useEffect(() => {
14 if (delay !== null) {
15 let id = setInterval(() => {
16 savedCallback.current()
17 }, delay)
18 return () => clearInterval(id)
19 }
20 }, [delay])
21}
22
23export default function App() {
24 const [count, setCount] = useState(0)

Callers 1

useInterval.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected