I am using react-select package and using a custom options array to populate the data (i.e it custom labels etc.)
I have seen a couple of solutions they are not using options props to set value or just use default array pattern to populate data and set value and get it onChange, however I am unable to get value in my case:
If I set value prop it doesn't let me select option
If I pass the same (option) => option.phaseText) onChange, it returns it as a string
const HandelChange = (obj) => { console.log(obj); }; const [dataPhase, setDataPhase] = useState([ { phaseID: 1, phaseText: "Item 1" }, { phaseID: 2, phaseText: "Item 2" }, { phaseID: 3, phaseText: "Item 3" }, { phaseID: 4, phaseText: "Item 4" }, { phaseID: 5, phaseText: "Item 5" }, ]); <Select isSearchable options={dataPhase} getOptionLabel={(option) => option.phaseText} getOptionValue={(option) => option.phaseText} className="diMultiSelect" classNamePrefix="diSelect" styles={styles} maxMenuHeight={150} value={(option) => option.phaseText} // this doesn't let me click options onChange={() => HandelChange((option) => option.phaseText)} // this returns (option) => option.phaseText) as a string />
I am new to React, surely I don't know all, please let me know what I am doing wrong.
Thanks in advance.