fix: 🐛

This commit is contained in:
codytseng 2024-12-24 13:08:40 +08:00
parent 31f70c2ab1
commit b5174df32c
4 changed files with 19 additions and 11 deletions

View file

@ -4,20 +4,27 @@ import client from '@/services/client.service'
export function useFetchRelayList(pubkey?: string | null) {
const [relayList, setRelayList] = useState<TRelayList>({ write: [], read: [] })
const [isFetching, setIsFetching] = useState(true)
useEffect(() => {
const fetchRelayList = async () => {
if (!pubkey) return
setIsFetching(true)
if (!pubkey) {
setIsFetching(false)
return
}
try {
const relayList = await client.fetchRelayList(pubkey)
setRelayList(relayList)
} catch (err) {
console.error(err)
} finally {
setIsFetching(false)
}
}
fetchRelayList()
}, [pubkey])
return relayList
return { relayList, isFetching }
}