bigbuffet-rw/packages/pl-hooks/lib/hooks/accounts/useAccountRelationship.ts
marcin mikołajczak 9aa8ded6c6 Make pl-hooks self-containted
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-10-17 21:08:50 +02:00

17 lines
581 B
TypeScript

import { useQuery } from '@tanstack/react-query';
import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client';
import { usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
const useAccountRelationship = (accountId?: string) => {
const queryClient = usePlHooksQueryClient();
const { client } = usePlHooksApiClient();
return useQuery({
queryKey: ['accounts', 'entities', accountId],
queryFn: async () => (await client.accounts.getRelationships([accountId!]))[0],
enabled: !!accountId,
}, queryClient);
};
export { useAccountRelationship };