title: Dynamically create dropdown menu options from array with react-bootstrap
body: <p>I'm building a drupal based e-commerce site right now and got stuck. Still new to react and coding in general, but trying to learn. So I've got all my data pulled in, using redux and rest api, and I'm getting my products, variations and attributes. The product page is setting a specific product based on url, and now I need to be able to select the different attributes via a dropdown menu. Currently I have a place holder dropdown that matches the one shown in react-bootstrap documentation. However, I need to be placing options in that dropdown based off of my array holding the attributes.</p>
  
  <p>I'm sure it's simple but I've been searching around and haven't found an answer yet that works. Hopefully you guys can help.</p>
  
  <p>As you look through the code, keep in mind that sizes = [] is the array I'm looking to place data from as the selectable options in the dropdown.</p>
  
  <p>Here's the product page:</p>
  
  <pre><code>import React, { Component} from 'react';
  import '../../css/Home.css';
  import MenuBar from "../sub-components/MenuBar";
  import LeftMenuBar from "../sub-components/LeftMenuBar";
  import "../../css/ProductPage.css"
  import WomensWear from "../../media/WomensWear.jpg"
  import {
      Dropdown,
      DropdownToggle,
      DropdownMenu,
      DropdownItem } from 'reactstrap';
  
  class ProductPage extends Component {
      constructor(props) {
          super(props);
  
          this.toggle = this.toggle.bind(this);
          this.state = {
              dropdownOpen: false
          };
      }
  
      toggle() {
          this.setState(prevState =&gt; ({
              dropdownOpen: !prevState.dropdownOpen
          }));
      }
  
      getProduct() {
  
          let product = null;
          let sizes = [];
          if (this.props.products &amp;&amp; this.props.products.items.length) {
              product = this.props.products.items.find(o =&gt; o.path[0].alias === this.props.router.match.url);
  
              if (product &amp;&amp; this.props.variations &amp;&amp; this.props.attributes) {
                  product.something = [];
                  for (let i = 0; i &lt; product.variations.length; i++) {
                      let varid = product.variations[i].target_id;
                      let variation = this.props.variations.items.find(o =&gt; o.variation_id[0].value === varid);
  
                      variation.size = this.props.attributes.items.find(o =&gt; o.attribute_value_id[0].value === variation.attribute_size[0].target_id);
  
                      sizes.push({value: variation.size.attribute_value_id[0].value, name: variation.size.name[0].value});
                      product.something.push(variation);
  
                      console.log(sizes);
                  }
              }
          }
          return product;
      }
  
  
      render() {
          let style = {
              height: this.props.height - 56,
          };
  
          let product = this.getProduct();
  
          let body = product &amp;&amp; product.body.length ? product.body[0].value : null;
  
          return (
              &lt;div className="App" id="default"&gt;
                  &lt;div className='MenuBar'&gt;
                      &lt;MenuBar/&gt;
                  &lt;/div&gt;
                  &lt;div&gt;
                      &lt;div style={style} className="ProductPage row no-gutters"&gt;
                          &lt;div className="col-xs-3 col-md-3"&gt;
                              &lt;LeftMenuBar/&gt;
                          &lt;/div&gt;
                          &lt;div className="outer col-xs-4 col-md-4"&gt;
                              &lt;div&gt;
                                  &lt;div id="ProductPlacement"&gt;
                                    &lt;img src={WomensWear} alt=""/&gt;
                                      &lt;div id="alternate-pics"&gt;
                                          &lt;div id="alt-pic"&gt;
                                          &lt;/div&gt;
                                          &lt;div id="alt-pic"&gt;
                                          &lt;/div&gt;
                                          &lt;div id="alt-pic"&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div className="col-xs-5 col-md-5"&gt;
                              &lt;div id="ImagePlacement"&gt;
                                  &lt;div className="ProductTitle"&gt;
                                      &lt;h1&gt;First Product&lt;/h1&gt;
                                  &lt;/div&gt;
                                  &lt;hr/&gt;
                                  &lt;div className="ProductDescription"&gt;
                                      &lt;div dangerouslySetInnerHTML={{__html: body}} /&gt;
                                  &lt;/div&gt;
                                  &lt;div id="options"&gt;
                                      &lt;div id="color"&gt;
                                      &lt;/div&gt;
                                      &lt;div id="color2"&gt;
                                      &lt;/div&gt;
                                      &lt;div id="color3"&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;div id="options"&gt;
                                      &lt;div&gt;
                                          &lt;Dropdown isOpen={this.state.dropdownOpen} toggle={this.toggle}&gt;
                                              &lt;DropdownToggle caret id="size-dropdown"&gt;
                                                  Size
                                              &lt;/DropdownToggle&gt;
                                              &lt;DropdownMenu&gt;
                                                  &lt;DropdownItem&gt;1&lt;/DropdownItem&gt;
                                                  &lt;DropdownItem&gt;3&lt;/DropdownItem&gt;
                                                  &lt;DropdownItem&gt;5&lt;/DropdownItem&gt;
                                              &lt;/DropdownMenu&gt;
                                          &lt;/Dropdown&gt;
                                          &lt;div className="AddToCart"&gt;
                                              &lt;button className="AddToCart"&gt;Add To Cart&lt;/button&gt;
                                              &lt;button className="Price"&gt;$34.99&lt;/button&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          );
      }
  }
  
  export default ProductPage;
  </code></pre>