UNPKG

bigblocks

Version:

Complete Bitcoin UI component library - authentication, social, wallet, market, inscriptions, and blockchain interactions for React

39 lines (38 loc) 1.2 kB
// useChannels Hook - Fetch and manage channels import { useQuery } from "@tanstack/react-query"; import { useApiClient } from "./useApiClient.js"; export function useChannels() { const apiClient = useApiClient(); const { data: channels = [], isLoading, error, refetch, } = useQuery({ queryKey: ["channels"], queryFn: async () => { return await apiClient.channels.list(); }, staleTime: 1000 * 60 * 5, // 5 minutes }); return { channels, isLoading, error, refetch, }; } export function useChannelMessages({ channelId = "", page = 1, limit = 20, enabled = true, }) { const apiClient = useApiClient(); const { data: messages = null, isLoading, error, refetch, } = useQuery({ queryKey: ["channelMessages", channelId, page, limit], queryFn: async () => { if (!channelId) return null; return await apiClient.messages.channel(channelId, page, limit); }, enabled: enabled && !!channelId, staleTime: 1000 * 60, // 1 minute }); return { messages, isLoading, error, refetch, }; }