Skip to content

Instantly share code, notes, and snippets.

@kanishkamakhija
Created April 19, 2020 18:06
Show Gist options
  • Save kanishkamakhija/17f15da8d9444ad5f3f52c756d6e855b to your computer and use it in GitHub Desktop.
Save kanishkamakhija/17f15da8d9444ad5f3f52c756d6e855b to your computer and use it in GitHub Desktop.
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