// src/features/profile/hooks/useProfile.ts import { useEffect, useState } from 'react'; import { useAuthSession } from '@/providers/AuthProvider'; import { profileService } from '@/features/profile/services/profileService'; import { UserProfile } from '@/features/profile/types'; export function useProfile() { const { user } = useAuthSession(); const [profile, setProfile] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const loadProfile = async () => { if (!user?.uid) { setProfile(null); setLoading(false); return; } try { setError(null); setLoading(true); const data = await profileService.getMyProfile(user.uid); setProfile(data); } catch (err: any) { setError(err?.message ?? 'No se pudo cargar el perfil'); } finally { setLoading(false); } }; useEffect(() => { loadProfile(); }, [user?.uid]); return { profile, loading, error, reload: loadProfile, }; }