Create books array (trial) - KatyaHorton/Udacity-MyReads-PROJECT GitHub Wiki

  1. Import BooksAPI:
import * as BooksAPI from './BooksAPI'
  1. Create books array in state of App.js:
  state = { 
 	books: []
  }
  1. Add props to BooksShelf and BooksSearch to access this.state.books from these components:
  books={this.state.books}
  1. 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.


  1. From fetch books from BooksShelf:
	<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>

NOTE!

For some reason, it brings the mistake to the file, though the code seems to work OK

⚠️ **GitHub.com Fallback** ⚠️