-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq2.tsx
More file actions
31 lines (29 loc) · 801 Bytes
/
q2.tsx
File metadata and controls
31 lines (29 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import * as React from 'react';
// You are building a photo hosting app in React. Your browser is running very slowly and sometimes freezes when running the code below. What should you do to fix this problem?
function PhotoAlbum() {
const [photos, setPhotos] = React.useState([]);
React.useEffect(() => {
async function fetchData() {
const photos
=
await fetch("/photos");
}
setPhotos (photos);
fetchData();
});
return (
<ul>
{photos.map((photo) => (
<li key={photo.id}>
<img src={photo.url} />
</li>
))}
</ul>
);
}
// Select the best option:
// A. Pass as a second argument into React.useEffect
// B. Pass [photos] as a second argument into React.useEffect
// C.
// Pass [setPhotos] as a second argument into React.useEffect
// D. Pass [setPhotos, photos] as a second argument into React.useEffect