6 changed files with 48 additions and 13 deletions
@ -0,0 +1,30 @@ |
|||||||
|
import client from '@/services/client.service' |
||||||
|
import { TRelayInfo } from '@/types' |
||||||
|
import { useEffect, useState } from 'react' |
||||||
|
|
||||||
|
export function useFetchRelayInfo(url: string) { |
||||||
|
const [isFetching, setIsFetching] = useState(true) |
||||||
|
const [relayInfo, setRelayInfo] = useState<TRelayInfo | undefined>(undefined) |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
const fetchRelayInfos = async () => { |
||||||
|
setIsFetching(true) |
||||||
|
const timer = setTimeout(() => { |
||||||
|
setIsFetching(false) |
||||||
|
}, 5000) |
||||||
|
try { |
||||||
|
const [relayInfo] = await client.fetchRelayInfos([url]) |
||||||
|
setRelayInfo(relayInfo) |
||||||
|
} catch (err) { |
||||||
|
console.error(err) |
||||||
|
} finally { |
||||||
|
clearTimeout(timer) |
||||||
|
setIsFetching(false) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fetchRelayInfos() |
||||||
|
}, [url]) |
||||||
|
|
||||||
|
return { relayInfo, isFetching } |
||||||
|
} |
||||||
Loading…
Reference in new issue