Skip to content

Commit f02d1cd

Browse files
committed
ProjectSelect. Do not render if empty list
1 parent b05ca3f commit f02d1cd

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/components/ProjectSelect.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React, { FunctionComponent } from "react";
22
import { MenuItem, Select } from "@material-ui/core";
3-
import {
4-
useProjectState,
5-
} from "../contexts/project.context";
3+
import { useProjectState } from "../contexts/project.context";
64
import { useHistory } from "react-router-dom";
75

86
const ProjectSelect: FunctionComponent<{
@@ -23,17 +21,21 @@ const ProjectSelect: FunctionComponent<{
2321
};
2422

2523
return (
26-
<Select
27-
id="project-select"
28-
value={selectedId}
29-
onChange={handleProjectSelect}
30-
>
31-
{projectState.projectList.map((project) => (
32-
<MenuItem key={project.id} value={project.id}>
33-
{project.name}
34-
</MenuItem>
35-
))}
36-
</Select>
24+
<React.Fragment>
25+
{projectState.projectList.length > 0 && (
26+
<Select
27+
id="project-select"
28+
value={selectedId}
29+
onChange={handleProjectSelect}
30+
>
31+
{projectState.projectList.map((project) => (
32+
<MenuItem key={project.id} value={project.id}>
33+
{project.name}
34+
</MenuItem>
35+
))}
36+
</Select>
37+
)}
38+
</React.Fragment>
3739
);
3840
};
3941

0 commit comments

Comments
 (0)