bigblocks
Version:
Complete Bitcoin UI component library - authentication, social, wallet, market, inscriptions, and blockchain interactions for React
42 lines (41 loc) • 1.29 kB
JavaScript
// useFetchLikes Hook - Fetch likes for posts
import { useQuery } from "@tanstack/react-query";
import { useApiClient } from "./useApiClient.js";
export function useFetchLikes({ txid, enabled = true, }) {
const apiClient = useApiClient();
const { data: likeInfo = null, isLoading, error, refetch, } = useQuery({
queryKey: ["likes", txid],
queryFn: async () => {
if (!txid)
return null;
return await apiClient.likes.forPost(txid);
},
enabled: enabled && !!txid,
staleTime: 1000 * 60, // 1 minute
});
return {
likeInfo,
isLoading,
error,
refetch,
};
}
export function useFetchUserLikes({ bapId, page = 1, limit = 20, enabled = true, }) {
const apiClient = useApiClient();
const { data: likesResponse = null, isLoading, error, refetch, } = useQuery({
queryKey: ["userLikes", bapId, page, limit],
queryFn: async () => {
if (!bapId)
return null;
return await apiClient.likes.byUser(bapId, page, limit);
},
enabled: enabled && !!bapId,
staleTime: 1000 * 60 * 5, // 5 minutes
});
return {
likesResponse,
isLoading,
error,
refetch,
};
}