Select Function Example

Starting point for creating JSFiddles with React.

HTML

<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<div id="container">
    <!-- This element's contents will be replaced with your component. -->
</div>

Babel + JSX

const SelectBox = ({ options }) => {
  const onOptionSelect = (e) => {
    console.log("selected", e.target.value);
  };

  return (
    <React.Fragment>
      <select onChange={(e) => onOptionSelect(e)}>
        {options.map((opt, key) => (
          <option key={key}>{opt}</option>
        ))}
      </select>
    </React.Fragment>
  );
};

const myOptions = ["a", "b", "c", "d"];

ReactDOM.render(
  <SelectBox options={myOptions} />,
  document.getElementById("container")
);