-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBookList.js
52 lines (41 loc) · 1.13 KB
/
BookList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { Component } from 'react';
import {StyleSheet, Image, FlatList, View, Text } from 'react-native';
import BookItem from "./BookItem";
import NYT from "./NYT";
class BookList extends Component {
constructor(props) {
super(props);
this.state = {
data: []};
};
componentDidMount() {
this._refreshData();
}
_renderItem = ({item}) => {
return (
<BookItem
coverURL={item.book_image}
title={item.key}
author={item.author}
/>
)
};
_addKeysToBooks = books => {
//뉴욕타임스 api 응답을 가져와서 렌더링을 위한 key 속성을 객체에 추가
return books.map(book => {
return Object.assign(book, {key: book.title});
});
};
_refreshData = () => {
NYT.fetchBooks().then(books => {
this.setState({data:this._addKeysToBooks(books)});
});
}
render() {
return <FlatList
data={this.state.data}
renderItem={this._renderItem}
/>
}
}
export default BookList;