import MultiSelect from "react-multi-select-component";
...
const [invoices,set_invoices] = useState([]);
const [selected, setSelected] = useState([]);
function test(options, filter) {
if (!filter) {
return options;
}
var data={'invoice_number':'22'}
axios.post('http://localhost:4000/get_invoice_by_number',data).then(
response => {
/* Matching the array elements to be like {lable:'',value:''} */
var temp_invoices=[];
for(var i =0;i<response.data.length;i++){
temp_invoices.push({
label:response.data[i].invoice_number,
value:response.data[i].invoice_number
})
}
/* This is updating the list with response.data that is coming from the API */
set_invoices(temp_invoices);
console.log('FIRED')
},error =>{
console.log(error);
}
)
return options;
}
<MultiSelect
options={invoices}
value={selected}
labelledBy={"Select"}
onChange={setSelected}
filterOptions={test}
/>