Skip to content

Instantly share code, notes, and snippets.

@vikpande
Last active October 24, 2017 18:03
Show Gist options
  • Save vikpande/067e15786e5b9a111598f679333aff79 to your computer and use it in GitHub Desktop.
Save vikpande/067e15786e5b9a111598f679333aff79 to your computer and use it in GitHub Desktop.
calling an API
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