Skip to content

Commit 5fc473c

Browse files
Linda PengLinda Peng
authored andcommitted
Support edge case in case API breaks -- if data.results is not returned from the API for some reason h/t Gaurav and Phil
1 parent b2ad22f commit 5fc473c

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/components/Resources/Resources.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ function Resources() {
2121

2222
const { results, count } = data;
2323

24+
const renderResults = () => {
25+
if (!results) return null; // to be on safe side in case API breaks
26+
return (
27+
<Grid container spacing={1}>
28+
{results && results.length === 0 ? (
29+
<Typography>No resources found</Typography>
30+
) : (
31+
results.map(resource => (
32+
<Grid item lg={3} key={resource.guid}>
33+
<ResourceCard {...resource} />
34+
</Grid>
35+
))
36+
)}
37+
</Grid>
38+
);
39+
};
40+
2441
return (
2542
<Grid container spacing={1}>
2643
<Grid item lg={3}>
@@ -36,21 +53,7 @@ function Resources() {
3653
</Typography>
3754
)}
3855
<br />
39-
{error ? (
40-
<div className="errorMessage">{error}</div>
41-
) : (
42-
<Grid container spacing={1}>
43-
{results.length === 0 ? (
44-
<Typography>No resources found</Typography>
45-
) : (
46-
results.map(resource => (
47-
<Grid item lg={3} key={resource.guid}>
48-
<ResourceCard {...resource} />
49-
</Grid>
50-
))
51-
)}
52-
</Grid>
53-
)}
56+
{error ? <div className="errorMessage">{error}</div> : renderResults()}
5457
</Grid>
5558
</Grid>
5659
);

0 commit comments

Comments
 (0)