Create books array (trial) - KatyaHorton/Udacity-MyReads-PROJECT GitHub Wiki
- Import
BooksAPI
:
import * as BooksAPI from './BooksAPI'
- Create books array in state of
App.js
:
state = {
books: []
}
- Add props to
BooksShelf
andBooksSearch
to accessthis.state.books
from these components:
books={this.state.books}
- Add
componentDidMount()
method:
componentDidMount(){
BooksAPI.getAll().then((books) => {
this.setState({ books: books})
})}
This function is going to invoked by react whenever that component is mounted to the view, calling BooksAPI.getAll() will return us a promise.
- From fetch
books
fromBooksShelf
:
<li>
<div className="book">
<div className="book-top">
<div className="book-cover" style={{ width: 128, height: 193, backgroundImage: `url(${book.imageLinks.smallThumbnail})` }}></div>
</div>
</div>
</li>
For some reason, it brings the mistake to the file, though the code seems to work OK