Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Map method doesn't work When I try duplicating <MenuItem />

I’m using material ui.

I try to duplicate <MenuItem /> as much as data.

So I wrote this code:

            <FormControl fullWidth>
              <InputLabel>JobArea</InputLabel>
              <Select
                autoFocus
                label="JobArea"
                sx={{
                  width: "70%",
                }}
              >
                {props.jobArea.map((jobArea: any) => {
                  <MenuItem key={jobArea.id} value={(jobArea || {}).name || ""}>
                    {(jobArea || {}).name || ""}
                  </MenuItem>;
                })}
              </Select>
            </FormControl>

But the code was nothing response.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It seems like <MenuItem> wasn’t read on program.

When I use console.log like this

                {props.jobArea.map((jobArea: any) => {
                  {
                    console.log((jobArea || {}).name || "");
                  }
                  <MenuItem key={jobArea.id} value={(jobArea || {}).name || ""}>
                    {(jobArea || {}).name || ""}
                  </MenuItem>;
                })}

Outcome was:

enter image description here

So I guess map method is fine but problem is <MenuItem>.

From Github they use map method like me.

https://github.com/mui/material-ui/issues/18494#issuecomment-680500105

What is deference between my code and others.

Please help me.

Thank you.

>Solution :

Your lambda passed to map has a statement body since it’s enclosed in curly braces. You need to return the menu item or use an expression lambda without curly braces.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading