mirror of
https://github.com/lumehq/lume.git
synced 2025-10-11 03:42:42 +02:00
34 lines
772 B
TypeScript
34 lines
772 B
TypeScript
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { useArk } from "./useArk";
|
|
|
|
export function useProfile(pubkey: string) {
|
|
const ark = useArk();
|
|
const queryClient = useQueryClient();
|
|
|
|
const {
|
|
isLoading,
|
|
isError,
|
|
data: user,
|
|
} = useQuery({
|
|
queryKey: ["user", pubkey],
|
|
queryFn: async () => {
|
|
const profile = await ark.getUserProfile(pubkey);
|
|
if (!profile)
|
|
throw new Error(
|
|
`Cannot get metadata for ${pubkey}, will be retry after 10 seconds`,
|
|
);
|
|
return profile;
|
|
},
|
|
initialData: () => {
|
|
return queryClient.getQueryData(["user", pubkey]);
|
|
},
|
|
refetchOnMount: false,
|
|
refetchOnWindowFocus: false,
|
|
refetchOnReconnect: false,
|
|
staleTime: Infinity,
|
|
retry: 2,
|
|
});
|
|
|
|
return { isLoading, isError, user };
|
|
}
|