'React-Select not working when options dont have label/values
I am using react-select and it is not working for me. My options come from an API fetch and it does not have value and label property. Is there any way to use existing JSON Array.
const awards = [{"name":"Award A","ID":1},{"name":"Award B","ID":2}]
<Select value={awards.name} options={awards} />
Does the options array need to have label and value property? I dont want to restructure my JSON Array. Any help?
Solution 1:[1]
You can use getOptionLabel
and getOptionValue
props to set the value and options.
For example:
<Select
getOptionLabel = {(option)=>option.name}
getOptionValue = {(option)=>option.id}
/>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | WebbH |