You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

31 lines
890 B

import { extractPubkeysFromEventTags } from '@/lib/tag'
import client from '@/services/client.service'
import { Event } from 'nostr-tools'
import { useEffect, useState } from 'react'
export function useFetchFollowings(pubkey?: string | null) {
const [followListEvent, setFollowListEvent] = useState<Event | null>(null)
const [followings, setFollowings] = useState<string[]>([])
const [isFetching, setIsFetching] = useState(true)
useEffect(() => {
const init = async () => {
try {
setIsFetching(true)
if (!pubkey) return
const event = await client.fetchFollowListEvent(pubkey)
if (!event) return
setFollowListEvent(event)
setFollowings(extractPubkeysFromEventTags(event.tags))
} finally {
setIsFetching(false)
}
}
init()
}, [pubkey])
return { followings, followListEvent, isFetching }
}