Skip to content

Instantly share code, notes, and snippets.

@FrankGerold
Created January 26, 2020 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrankGerold/3f2d82616c61455b875735991f0a8dda to your computer and use it in GitHub Desktop.
Save FrankGerold/3f2d82616c61455b875735991f0a8dda to your computer and use it in GitHub Desktop.
Book Search with Hooks
import React, { useState, useEffect } from 'react';
const BookSearch = (props) => {
// Set Book List state variable with State Hook
const [bookList, setBookList] = useState([])
useEffect(() => {
fetch('https://www.googleapis.com/books/v1/volumes?q=react+JS+hooks')
.then(response => response.json())
.then((searchResults) => {
//Set book list in state to list of search result items
setBookList(searchResults.items)
})
})
return (
<div>
{/*Map out an unordered list of each search result's title*/}
<ul>
{bookList.map((book) => {
return <li>{book.volumeInfo.title}</li>
})}
</ul>
</div>
);
}
export default BookSearch;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment