Skip to content

Instantly share code, notes, and snippets.

@vikrantnegi
Created February 18, 2020 12:31
Show Gist options
  • Save vikrantnegi/a244c61a4623c89b844b191b4f102403 to your computer and use it in GitHub Desktop.
Save vikrantnegi/a244c61a4623c89b844b191b4f102403 to your computer and use it in GitHub Desktop.
useEffect(() => {
fetch("https://www.googleapis.com/books/v1/volumes/?maxResults=30&q=danbrown")
.then(response => response.json())
.then(responseJson => {
const { items } = responseJson;
const booksList = items.map(book => {
const {
volumeInfo: { title, authors, imageLinks },
id: bookId
} = book;
return {
bookId,
thumbnail: imageLinks
? imageLinks.thumbnail
: "https://i.ibb.co/YLC0nQQ/not-found.png",
title,
authors: authors ? authors.toString().replace(/,/g, ", ") : "-"
};
});
setBooks(booksList);
setDataFetched(true);
})
.catch(error => {
console.error(error);
});
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment