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"
/>
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.