import { useQuery } from '@tanstack/react-query'; import { useNostr } from '@nostrify/react'; /** * Hook to fetch a user's follow list (kind 3 event). * Returns the latest kind 3 event for the given pubkey. */ export function useFollowList(pubkey: string | undefined) { const { nostr } = useNostr(); return useQuery({ queryKey: ['follow-list', pubkey], queryFn: async (c) => { if (!pubkey) return null; const signal = AbortSignal.any([c.signal, AbortSignal.timeout(5000)]); const events = await nostr.query( [{ kinds: [3], authors: [pubkey], limit: 1 }], { signal } ); return events[0] || null; }, enabled: !!pubkey, staleTime: 300000, // 5 minutes gcTime: 600000, // 10 minutes }); }