I have a multiselect dropdown. whenever I select an option I need to add that data to state. when I click the first option I get data like
[{id:"1", name:"Ind"}]
when I click the second option I get data like (currently two options are selected)
[{id:"1", name:"Ind"}, {id:"2", name:"Aus"}]
this.state = {
selectedCountries: []
};
in the onChange of multiselect I call the below function
handleChange = (options) => {
var output = [];
if(options !== null && options !== undefined){
console.log(options); // [{id:"1", name:"Ind"}, {id:"2", name:"Aus"}]
this.setState(prevState => {
selectedCountries:options
});
}
};
Its not working.
I am expecting it like this
selectedCountries:[
{
id:"1",
name:"Ind"
},
{
id:"2",
name:"Aus"
}
]
How to achieve this through reactjs?