Initial commit from Create Next App

This commit is contained in:
Joshua Seigler 2020-02-18 13:52:21 -05:00
commit 5684ef36ec
10 changed files with 7925 additions and 0 deletions

19
lib/useInterval.js Normal file
View file

@ -0,0 +1,19 @@
import { useEffect, useRef } from 'react'
// https://overreacted.io/making-setinterval-declarative-with-react-hooks/
const useInterval = (callback, delay) => {
const savedCallback = useRef()
useEffect(() => {
savedCallback.current = callback
}, [callback])
useEffect(() => {
const handler = (...args) => savedCallback.current(...args)
if (delay !== null) {
const id = setInterval(handler, delay)
return () => clearInterval(id)
}
}, [delay])
}
export default useInterval