3 review comments
export async function fetchUserData(userId: string) { const response = await fetch(`/api/users/${userId}`);Missing error handling here. What happens if the fetch fails or returns a 404?
const response = await fetch(`/api/users/${userId}`);
if (!response.ok) {
throw new Error(`Failed to fetch user: ${response.status}`);
}
const data = await response.json(); const data = await response.json(); return data;} export function UserProfile({ userId }: { userId: string }) { const [user, setUser] = useState(null);This should be typed properly. Using null as initial state can cause type issues.
const [user, setUser] = useState<User | null>(null); useEffect(() => { fetchUserData(userId).then(setUser);Potential memory leak - missing cleanup if component unmounts during fetch.
}, [userId]); if (!user) return <div>Loading...</div>; return <div>{user.name}</div>;}