Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { Platform, StyleSheet, Text, View, FlatList } from 'react-native';
  3. import axios from 'axios'
  4. import { ScrollView } from 'react-native-gesture-handler';
  5.  
  6.  
  7. export default class App extends Component {
  8.  
  9. state = {
  10. data: []
  11. }
  12.  
  13. _userData = async () => {
  14. await axios.get('http://localhost:3000/api/v1/cariKost/users')
  15. .then(response => {
  16. this.setState({
  17. data: response.data
  18. })
  19. })
  20. .then(error => console.log(error))
  21. }
  22. componentDidMount() {
  23. // this.fetchData();
  24. this._userData()
  25. }
  26. render() {
  27. return (
  28. <View >
  29. <Text>Welcome</Text>
  30. <ScrollView>
  31. {this.state.data.map((user, index) => {
  32. return (
  33. <View key={index} style={{ backgroundColor: '#abc123', padding: 10, margin: 10 }}>
  34. <Text style={{ color: '#fff', fontWeight: 'bold' }}>{user.name}</Text>
  35. <Text style={{ color: '#fff' }}>{user.password}</Text>
  36. </View>
  37. )
  38. })}
  39. </ScrollView>
  40.  
  41. </View>
  42. );
  43. }
  44. }
  45.  
  46. const styles = StyleSheet.create({
  47. container: {
  48. flex: 1,
  49. justifyContent: 'center',
  50. alignItems: 'center',
  51. backgroundColor: '#F5FCFF',
  52. },
  53. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement