Reputation: 47
So I'm working With React Multiple Select to enable a dropdown list that allows multiple selections, I want it to show data from the server a but it brings it as one single string. Tried the next two ways:
const [selected, setSelected] = useState([]);
const options = hours?.map ((list, index) => {return list})
const listOfHours = [{label: options, value: options}]
<MultiSelect
options={listOfHours}
value={selected}
onChange={setSelected}
labelledBy="Select"
/>
const [selected, setSelected] = useState([]);
const listOfHours = [{label: settings?.time, value: settings?.time}]
<MultiSelect
options={listOfHours}
value={selected}
onChange={setSelected}
labelledBy="Select"
/>
Upvotes: 0
Views: 33
Reputation: 1227
options
should be an array of objects:
const listOfHours = hours.map(hour => ({label:hour.time, value:hour.time}))
what you were doing there is giving options
an array of one object
Upvotes: 1