/** * Company Query Hook * * Fetches a single company by ID using TanStack Query. * Replaces CompanyRepository + GetCompanyUseCase pattern. * * @layer Presentation - Hooks */ import { useQuery } from '@tanstack/react-query'; import { companiesApi } from '@/infrastructure/http/api/company'; import { queryKeys } from '@/lib/query-keys'; /** * useCompany * * Fetches and caches a single company by ID. * * @param companyId - Company UUID (optional for conditional fetching) * @returns Query result with company data, loading, and error states * * @example * ```typescript * function CompanyProfile({ companyId }: { companyId: string }) { * const { data: company, isLoading, error } = useCompany(companyId); * * if (isLoading) return ; * if (error) return ; * if (!company) return null; * * return
{company.name}
; * } * ``` */ export function useCompany(companyId: string | undefined) { return useQuery({ queryKey: queryKeys.companies.detail(companyId!), queryFn: async () => { const company = await companiesApi.getCompany(companyId!); return company; }, enabled: !!companyId, staleTime: 5 * 60 * 1000, // 5 minutes }); }