Created
January 26, 2020 21:21
-
-
Save FrankGerold/3f2d82616c61455b875735991f0a8dda to your computer and use it in GitHub Desktop.
Book Search with Hooks
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
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