I'm trying to use react-select, https://react-select.com/, and the mandatory format for the options prop seems to be {value:something, label:something}.
I have a list of objects with other key,value pairs and my question is if there is any workaround for me not having to modify the array because if i modify it, it means that the select component will not return an object of the initial array so i will have to map them again.
options = [
{name: 'opt1', descr:'descr1'},
{name: 'opt2', descr:'descr2'},
{name: 'opt3', descr:'descr3'},
]
In Vue i get to choose the key that will be used as label, for example.
Vue:
:items="options.name"
In react i would have to do something like:
this.new_options = []
this.options.forEach(element => {
this.new_options.push({
value : element.name,
label : element.name,
})
})
And in Select:
<Select
name="selectedWires"
//closeMenuOnSelect={false}
components={makeAnimated()}
onChange={this.handleSelectChange('selectedWires')}
options={this.new_options}
isMulti
/>
objectof the copied array, which i have to map to the corresponding object of the initial array, right?{name: 'opt1', descr:'descr1'}and not{value:'opt1', label:'opt1'}. If i send the latter, i'll have to search the db and compare name with value.valueanddescrin the backend? why don't you serialize that in the value, and keep the label only with the name