I have this React code:
componentDidMount(){
this.getBooks();
}
getBooks(){
axios.get('http://localhost:8000/api/v1/books')
.then(res => {
this.setState({books: res.data});
})
}
deleteBookHandler(id){
axios.delete(`http://localhost:8000/api/v1/book/${id}`)
.then(() => {
this.getBooks();
})
}
When I use this.getBooks() inside componentDidMount, everything works fine, but when I use the same function inside deleteBookHandled, which is a function I perform when the delete button on one of my grid items is pressed, React throws this error:
Unhandled Rejection (TypeError): _this3.getBooks is not a function
Maybe I'm not understanding properly the this keyword on JavaScript. Where's the error? How can I call getBooks inside 'then'?