UNPKG

bigblocks

Version:

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

42 lines (41 loc) 1.29 kB
// useFetchPost Hook - Fetch a single post by transaction ID import { useQuery } from "@tanstack/react-query"; import { useApiClient } from "./useApiClient.js"; export function useFetchPost({ txid, enabled = true, }) { const apiClient = useApiClient(); const { data: post = null, isLoading, error, refetch, } = useQuery({ queryKey: ["post", txid], queryFn: async () => { if (!txid) return null; return await apiClient.posts.single(txid); }, enabled: enabled && !!txid, staleTime: 1000 * 60 * 5, // 5 minutes }); return { post, isLoading, error, refetch, }; } export function useFetchReplies({ txid = "", page = 1, limit = 20, enabled = true, }) { const apiClient = useApiClient(); const { data: replies = null, isLoading, error, refetch, } = useQuery({ queryKey: ["replies", txid, page, limit], queryFn: async () => { if (!txid) return null; return await apiClient.posts.replies(txid, page, limit); }, enabled: enabled && !!txid, staleTime: 1000 * 60 * 2, // 2 minutes }); return { replies, isLoading, error, refetch, }; }