/** * Company Detail Hook * * Fetches company details with caching for efficient data access. */ import { useQuery } from '@tanstack/react-query'; import { supabase } from '@/integrations/supabase/client'; import { queryKeys } from '@/lib/queryKeys'; export function useCompanyDetail(slug: string | undefined, companyType: string) { return useQuery({ queryKey: queryKeys.companies.detail(slug || '', companyType), queryFn: async () => { if (!slug) return null; const { data, error } = await supabase .from('companies') .select('*') .eq('slug', slug) .eq('company_type', companyType) .maybeSingle(); if (error) throw error; return data; }, enabled: !!slug, staleTime: 5 * 60 * 1000, // 5 minutes gcTime: 15 * 60 * 1000, refetchOnWindowFocus: false, }); }