Last active
October 24, 2017 18:03
-
-
Save vikpande/067e15786e5b9a111598f679333aff79 to your computer and use it in GitHub Desktop.
calling an API
This file contains hidden or 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, { Component } from 'react'; | |
| import * as BooksAPI from './BooksAPI'; | |
| import ShelfComponent from './ShelfComponent'; | |
| class App extends Component { | |
| state = { | |
| books: [] | |
| } | |
| componentDidMount(){ | |
| BooksAPI.getAll().then(booksfromServer=> this.setState({books:booksfromServer})) | |
| } | |
| render() { | |
| return ( | |
| <div> | |
| <ShelfComponent title= "Currently Reading" books= {this.state.books.filter(book=>book.shelf==="currentlyReading")}/> | |
| <ShelfComponent title= "Want to Read" books= {this.state.books.filter(book=>book.shelf==="wantToRead")}/> | |
| <ShelfComponent title= "Read" books= {this.state.books.filter(book=>book.shelf==="read")}/> | |
| </div> | |
| ); | |
| } | |
| } | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment