@lifi/widget
Version:
LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.
22 lines (17 loc) • 526 B
text/typescript
import { useEffect, useRef } from 'react'
export function useInterval(callback: () => void, delay: number) {
const callbacRef = useRef<() => void>(null)
// update callback function with current render callback that has access to latest props and state
useEffect(() => {
callbacRef.current = callback
})
useEffect(() => {
if (!delay) {
return () => {}
}
const interval = setInterval(() => {
callbacRef.current?.()
}, delay)
return () => clearInterval(interval)
}, [delay])
}