react-native-scalable-analog-clock
Version:
Scalable analog clock face.
22 lines (19 loc) • 627 B
text/typescript
import React, { useState, useEffect, useRef } from "react"
// From Dan Abramov https://overreacted.io/making-setinterval-declarative-with-react-hooks/
export function useInterval(callback, delay) {
const savedCallback = useRef(null)
// Remember the latest callback.
useEffect(() => {
savedCallback.current = callback
}, [callback])
// Set up the interval.
useEffect(() => {
function tick() {
savedCallback.current()
}
if (delay !== null) {
let id = setInterval(tick, delay)
return () => clearInterval(id)
}
}, [delay])
}