<select value={this.state.selectedValue} onChange={this.handleChange} size={5}>
<option value="grapefruit">Grapefruit</option>
<option value="lime">Lime</option>
<option value="coconut">Coconut</option>
<option value="mango">Mango</option>
</select>
changecountry(value){
//some code here
}
handlechange = (event) => {
let value = event.target.value
setTimeout(function (){
this.changecountry(value)
}
}, 300);
I am trying to call changecountry inside setTimeout function.
getting this.changecountry is not a function error
what is wrong with this code?
>Solution :
Update your setTimeout to
setTimeout(() => this.changecountry(value) , 300);
this context will change inside function(){} in setTimeout. Arrow Function
is lexical scoped, will take reference from where it was created.