I have a select component:
<Select}>
{data &&
data.map((survey) => (
<Option key={survey.id} value={survey.id}>
{survey.name}
</Option>
))
}
</Select>
The data array is coming from an API fetch using axios, which is then saved in the state data:
const [data, setData] = useState([]);
How do I grab the selected value and display it?
I tried adding an onChange handler to the component and save the e.target.value in a separate piece of state:
onChange={e => setInput(e?.target?.value)}
However, I'm getting an error that value is undefined. I suspect it's because the data hasn't loaded yet.
How do you get the selected value from the options when the options are coming from an API? (i.e., dynamic dropdown)