title: React Creating Dynamic Select and Option Elements with Material-UI
body: <p>So, I honestly thought this would take me 15 minutes, but I'm up around 5 hours right now. What's bothering me so much is that I know it's a simple solution, and I've tried a few different approaches as well.</p>
  <p>I have a React App, and inside the Diagnosis Component, I have two dropdown elements that allow users to choose the Make and Model of their appliance. What I'm trying to do is allow the user to choose which Make they have, and when the make dropdown is selected, the models dropdown populates automatically.</p>
  <p>Here is my MakeandModel.js file:</p>
  <pre><code>import React, { useState, useEffect } from 'react';
  import { makeStyles } from '@material-ui/core/styles';
  import FormControl from '@material-ui/core/FormControl';
  import InputLabel from '@material-ui/core/InputLabel';
  import Select from '@material-ui/core/Select';
  import MenuItem from '@material-ui/core/MenuItem';
  
  import makeandmodel_DATA from './makeandmodel_DATA';
  
  const useStyles = makeStyles((theme) =&gt; ({
      formControl: {
        margin: theme.spacing(1),
        minWidth: 120,
      },
      selectEmpty: {
        marginTop: theme.spacing(2),
      },
  }));
  
  console.log(makeandmodel_DATA);
  
  export default () =&gt; {
      const classes = useStyles();
      const [data, setData] = useState();
      const [make, setMake] = useState('');
      const [model, setModel] = useState('');
  
      useEffect(() =&gt; {
          
      });
  
      const handleMakeChange = (event) =&gt; (
          setMake(event.target.value)
      );
  
      const handleModelChange = (event) =&gt; (
          setModel(event.target.value)
      );
  
      return (
          &lt;&gt;
              &lt;FormControl variant=&quot;outlined&quot; className={classes.formControl}&gt;
                  &lt;InputLabel id=&quot;demo-simple-select-outlined-label&quot;&gt;Make&lt;/InputLabel&gt;
                  &lt;Select
                      labelId=&quot;demo-simple-select-outlined-label&quot;
                      id=&quot;demo-simple-select-outlined&quot;
                      value={make}
                      onChange={handleMakeChange}
                      label=&quot;Make&quot;
                  &gt;
                      &lt;MenuItem value=&quot;&quot;&gt;
                          &lt;em&gt;Choose a Make&lt;/em&gt;
                      &lt;/MenuItem&gt;
                      {makeandmodel_DATA.map((make, index) =&gt; (
                          &lt;MenuItem key={index} value={make.name}&gt;{make.name}&lt;/MenuItem&gt;
                      ))}
                  &lt;/Select&gt;
              &lt;/FormControl&gt;
  
              &lt;FormControl variant=&quot;outlined&quot; className={classes.formControl}&gt;
                  &lt;InputLabel id=&quot;demo-simple-select-outlined-label&quot;&gt;Model&lt;/InputLabel&gt;
                  &lt;Select
                      labelId=&quot;demo-simple-select-outlined-label&quot;
                      id=&quot;demo-simple-select-outlined&quot;
                      value={model}
                      onChange={handleModelChange}
                      label=&quot;Model&quot;
                  &gt;
                      &lt;MenuItem value=&quot;&quot;&gt;
                          &lt;em&gt;Choose a Model&lt;/em&gt;
                      &lt;/MenuItem&gt;
                      
                  &lt;/Select&gt;
              &lt;/FormControl&gt;
              &lt;br /&gt;
         &lt;/&gt;
      );
  };
  </code></pre>
  <p>I also have some sample data I'm importing to try to populate my Make and Model dropdowns. Here is the code from the makeandmodel_DATA.json file:</p>
  <pre><code>[
      {
          &quot;name&quot;: &quot;Dyson&quot;,
          &quot;models&quot;: [
              {
                  &quot;name&quot;: &quot;v12&quot;
              },
              {
                  &quot;name&quot;: &quot;v10&quot;
              },
              {
                  &quot;name&quot;: &quot;ball&quot;
              }
          ]
      },
      {
          &quot;name&quot;: &quot;Oreck&quot;,
          &quot;models&quot;: [
              {
                  &quot;name&quot;: &quot;Upright&quot;
              },
              {
                  &quot;name&quot;: &quot;Unique&quot;
              },
              {
                  &quot;name&quot;: &quot;XL&quot;
              }
          ]
      },
      {
          &quot;name&quot;: &quot;Electrolux&quot;,
          &quot;models&quot;: [
              {
                  &quot;name&quot;: &quot;Classic&quot;
              },
              {
                  &quot;name&quot;: &quot;Vintage&quot;
              },
              {
                  &quot;name&quot;: &quot;New School&quot;
              }
          ]
      },
      {
          &quot;name&quot;: &quot;Kirby&quot;,
          &quot;models&quot;: [
              {
                  &quot;name&quot;: &quot;Heavy&quot;
              },
              {
                  &quot;name&quot;: &quot;Light&quot;
              },
              {
                  &quot;name&quot;: &quot;Regular&quot;
              }
          ]
      },
      {
          &quot;name&quot;: &quot;Hoover&quot;,
          &quot;models&quot;: [
              {
                  &quot;name&quot;: &quot;Windtunnel&quot;
              },
              {
                  &quot;name&quot;: &quot;Back&quot;
              },
              {
                  &quot;name&quot;: &quot;Upright&quot;
              }
          ]
      }
  ]
  </code></pre>
  <p>I've tried to map over the imported data, but every time I do that to find the models, I end up returning undefined.</p>
  <p>I've also tried to wire up the useEffect function, but couldn't figure out exactly to wire it up correctly that way either.</p>
  <p>Like I said, I feel like the solution is super simple, but I'm overlooking something fundamental. I'm really just looking for a super simple solution that looks clean and works well. If you need any other information to help us solve this problem, just ask.</p>
  <p>Thanks in advance!</p>