Hi, I get an array from API, but it does not have properties such as 'label' or 'value'. How can I choose which property is belongs to label and value, without changing the array?
Example:
I have this:
options = [{ name: "Black", id: 1 }, { name: "White", id: 2 } ];
Examples from react-select:
options = [{ label: "Black", value: 1 }, { label: "White", value: 2 } ];
Regards
options = options.map(option => {label: option.name, value: option.id});
I had a similar object setup and solved it with these props on the Select component:
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.id}
Works fine. Thanks so much @jdt3969 !
Most helpful comment
I had a similar object setup and solved it with these props on the Select component: