Created
April 19, 2020 18:06
-
-
Save kanishkamakhija/17f15da8d9444ad5f3f52c756d6e855b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const update = (book, shelf) => | |
fetch(`${api}/books/${book.id}`, { | |
method: 'PUT', | |
headers: { | |
...headers, | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ shelf }) | |
}).then(res => res.json()) | |
updateState = (res) => { | |
console.log(res); // defined | |
this.setState({currentlyReadingBooks: res.currentlyReadingBooks, // undefined | |
wantToReadBooks : res.wantToReadBooks, | |
readBooks: res.readBooks}); | |
} | |
updateBookShelf = (book, shelf) => { | |
const promise = BooksAPI.update(book, shelf); | |
promise.then((data) => | |
this.updateState(data)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment