Added onResultSelect to app.js to add search-returned book to state

This commit is contained in:
Ken Jannette
2018-04-19 18:50:39 -04:00
parent f9f8b49b5b
commit e9e73ead9c

View File

@@ -27,8 +27,24 @@ class BooksApp extends React.Component {
} }
onResultSelect = (e) => { onResultSelect = (e) => {
console.log("onResultSelect")
this.history.push('/'); const books = this.state.books
const id = e.target.name
const newShelf = e.target.value
const results = this.state.results
let newBook
results.forEach((result) => {
if (result.id === id) {
newBook = result
newBook.shelf = newShelf
}
});
this.setState({
books: [...newBook]
})
} }
onSelectChange = (e) => { onSelectChange = (e) => {