I have a react select component that isn't recognizing the default value option. The code looks like this:
renderPlans(){
if(this.props.plans){
let list = this.props.plans.map(item=>{
return ({label:item.description, value:item.id})
});
return(
<Select
name= "tile-plans"
value= {this.state.selected}
classNamePrefix='react-select-container'
options={list}
defaultValue={list[0]}
onChange={(e) => { e ? this.setState({selected: e.value}) : this.setState({selected: ''}) }}
/>
)
}
}
from everything I can find on its docs this is the format to give it. Basically I just want the first option to always be the default choice as there will be times when there is only 1 option and it doesn't make sense for someone to need to select a drop down. I also have a graph that's being loaded underneath so if an option is selected the graph won't load.
This isn't a duplicate question as I know you can do it like this:
value= {this.state.selected ? this.state.selected:list[0].label}
but it's not working. The input remains blank on load.