This block + 6,000 more — yours with Pro

Comments Code Review

26/100
Docs

UserProfile.tsx

3 review comments

Changes requested
1
export async function fetchUserData(userId: string) {
2
  const response = await fetch(`/api/users/${userId}`);
AC
Alex Chen2h ago

Missing error handling here. What happens if the fetch fails or returns a 404?

Suggested change
const response = await fetch(`/api/users/${userId}`);
if (!response.ok) {
  throw new Error(`Failed to fetch user: ${response.status}`);
}
const data = await response.json();
3
  const data = await response.json();
4
  return data;
5
}
6
 
7
export function UserProfile({ userId }: { userId: string }) {
8
  const [user, setUser] = useState(null);
SK
Sarah Kim1h ago

This should be typed properly. Using null as initial state can cause type issues.

Suggested change
const [user, setUser] = useState<User | null>(null);
9
  
10
  useEffect(() => {
11
    fetchUserData(userId).then(setUser);
MR
Mike Rodriguez30m ago

Potential memory leak - missing cleanup if component unmounts during fetch.

12
  }, [userId]);
13
 
14
  if (!user) return <div>Loading...</div>;
15
  return <div>{user.name}</div>;
16
}
Click line numbers to view comments3 threads