-
Notifications
You must be signed in to change notification settings - Fork 0
/
55_get_data_with_buttons.js
59 lines (48 loc) · 1.24 KB
/
55_get_data_with_buttons.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
import React,{useEffect,useState} from 'react';
import {Platform,Button, TextInput,Text,StatusBar, View,ActivityIndicator,StyleSheet,Modal,Pressable,ScrollView,FlatList } from 'react-native';
import axios from 'axios';
const App = () => {
const [data,setData]=useState([])
const getAPIData = async ()=>{
const url = "http://10.0.2.2:3000/users";
let result = await fetch(url);
result = await result.json();
console.warn(result);
if(result){
setData(result)
}
}
useEffect(()=>{
getAPIData();
},[])
return (
<View style={styles.container}>
{
data.length?
data.map((item)=>{
return (
<View style={styles.dataWrapper}>
<View style={{flex:1}}><Text>{item.name}</Text></View>
<View style={{flex:1}}><Text>{item.age}</Text></View>
<View style={{flex:1}}> <Button title='Delete' ></Button></View>
<View style={{flex:1}}> <Button title='Edit' ></Button></View>
</View>
)
}):null
}
</View>
);
};
const styles=StyleSheet.create({
container:{
flex:1,
},
dataWrapper:{
flexDirection:'row',
justifyContent:'space-around',
backgroundColor:'lightgrey',
margin:10,
padding:5
}
})
export default App;