PR REVIEWReact useEffect Infinite Loop#847FigmaVercel
00:00Junior~10 min
PULL REQUEST
Open#847 · 1 commit
React useEffect Infinite Loop
junior-dev-99 wants to mergefeature/profile-eager-loadmain
JU
junior-dev-99
1 file changed · 3 hours ago
YOUR MISSION
A junior dev reorganised the data-fetch logic inside a React component. QA reports the browser freezes instantly when loading the profile page. Spot the bug in the PR diff.
Junior~10 min
HINTS (0/3 used)
REVIEWING AS
SR
Senior Engineer
@ Figma · Backend Platform
src / components / UserProfile.tsx+3 2
5
5
export function UserProfile({ userId }: Props) {
6
6
const [profile, setProfile] = useState<UserProfile | null>(null);
7
7
const [loading, setLoading] = useState(true);
8
+
const userQuery = { userId, includeActivity: true };
+
8
9
9
10
useEffect(() => {
10
11
setLoading(true);
11
api.fetchProfile(userId).then((p) => {
+
12
+
api.fetchProfile(userQuery).then((p) => {
+
12
13
setProfile(p);
13
14
setLoading(false);
14
15
});
15
}, [userId]);
+
16
+
}, [userQuery]);
+
16
17
17
18
if (loading) return <Spinner />;
18
19
return <UserCard profile={profile} />;
Click any changed line (+/−) to flag an issue · or Approve if everything looks safe