How do you create a very, very simple dropdown select with React? Nothing seem to work.
I have an array: var num = [1,2,3,4,5]
Function:
num(e){
this.setState({selected: e.target.value});
}
In the render:
<select option="{num}" value={this.state.selected} onChange={this.num} />
No error message, no nothing. I normally use npm plugin for this but I only need something basic.
Setting option={num}
will not work in jsx. You need to use <option>
tags:
Something like this is what you are after:
<select name="select" onChange={this.num}>
{num.map(function(n) {
return (<option value={n} selected={this.state.selected === n}>{n}</option>);
})}
</select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With