Whenever I try to execute this.fetchData();
, I encounter the error "TypeError: this.fetchData is not a function". Initially, I suspected that the context of 'this' was lost so I attempted using bind
and arrow functions without success. How can I troubleshoot this issue?
class ShowResults extends Component {
getData() {
return setTimeout(function() {
this.fetchData();
}, 2000); //I tried using .bind(this) but it didn't work
}
}
async fetchData() {
//code
}
}