From e9e73ead9c71425018f604e4c57e1dc8356d99bd Mon Sep 17 00:00:00 2001 From: Ken Jannette Date: Thu, 19 Apr 2018 18:50:39 -0400 Subject: [PATCH] Added onResultSelect to app.js to add search-returned book to state --- src/App.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 6a0bfd4..08cc2b9 100755 --- a/src/App.js +++ b/src/App.js @@ -27,8 +27,24 @@ class BooksApp extends React.Component { } 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) => {