-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
43 lines (38 loc) · 1.01 KB
/
App.js
File metadata and controls
43 lines (38 loc) · 1.01 KB
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
import React from 'react';
import { View, Text, FlatList } from 'react-native';
export default class App extends React.Component {
state = {
items: [],
isLoading: false
}
renderRow = ({ item }) => {
return (
<View style={{ padding: 10, borderBottomWidth: 1, borderBottomColor: '#ccc' }}>
<Text>{item.id}) {item.title}</Text>
</View>
)
}
componentDidMount(){
this.getData()
}
getData = () => {
let API_URL = 'https://jsonplaceholder.typicode.com/posts';
this.setState({isLoading:true})
fetch(API_URL).then(res => res.json()).then(res => {
this.setState({ items: res })
}).finally(()=> this.setState({isLoading:false}))
}
render() {
return (
<View style={{ flex: 1, marginTop: 50 }}>
<FlatList
data={this.state.items}
renderItem={this.renderRow}
refreshing={this.state.isLoading}
onRefresh={this.getData}
keyExtractor={(i, k) => k.toString()}
/>
</View>
)
}
}