React

by fulviocanducci

HTML

<div id="app"></div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

li {
  margin: 8px 0;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

.done {
  color: rgba(0, 0, 0, 0.3);
  text-decoration: line-through;
}

input {
  margin-right: 5px;
}

React

const data = [
	{'label': 'select 1', 'value': 1},
  {'label': 'select 2', 'value': 2}
];
function App() {
  const [items, setItems] = React.useState(data);
  const [selectItem, setSelectItem] = React.useState(0);
	return (
  	<div>
      <h3>{selectItem}</h3>
	    <select value={selectItem} onChange={e => setSelectItem(+e.target.value)}>
        <option value={0}>Selecione</option>
	      {items && items.map((item, i)=>(
        	<option value={item.value}>{item.label}</option>
        ))}
	    </select>        
	  </div>
  );
}
ReactDOM.render(<App />, document.querySelector("#app"))