-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
84 lines (63 loc) · 1.59 KB
/
api.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import React, { Component } from 'react';
import { View, Text, SafeAreaView ,ActivityIndicator,FlatList} from 'react-native';
import axios from 'axios';
export default class api extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
empdata: [],
}
}
getRequest()
{
console.warn("inside getrequest");
axios.get('https://jsonplaceholder.typicode.com/users')
.then((response) => {
console.log("data=>", response.data);
console.warn("ionvoked" + response.data.length);
var temp=[];
for(var i = 0; i < response.data.length; i++) {
temp[i]= JSON.parse(JSON.stringify(response.data[i]))
}
console.warn("temp" + temp.length);
this.setState({
empdata:temp,
isLoading:false
});
})
.catch(error => { console.log(error);
console.warn("error",error)
});
}
componentDidMount() {
this.getRequest();
//this.postRequest();
}
render(){
if(this.state.isLoading){
return(
<SafeAreaView style={{flex: 1, padding: 20}}>
<ActivityIndicator/>
<Text>
isLoading.....
</Text>
</SafeAreaView>
)
}else{
return(
<SafeAreaView style={{flex: 1, paddingTop:20}}>
<FlatList
data={this.state.empdata}
renderItem={({item,index}) => <Text style={{padding:5,elevation:5,}}>{item.id}, {item.name}</Text>}
keyExtractor={({id}, index) => id}
/>
</SafeAreaView>
);
}
}
}
function MyCoustumList(){
render(
);
}