Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- import { Platform, StyleSheet, Text, View, FlatList } from 'react-native';
- import axios from 'axios'
- import { ScrollView } from 'react-native-gesture-handler';
- export default class App extends Component {
- state = {
- data: []
- }
- _userData = async () => {
- await axios.get('http://localhost:3000/api/v1/cariKost/users')
- .then(response => {
- this.setState({
- data: response.data
- })
- })
- .then(error => console.log(error))
- }
- componentDidMount() {
- // this.fetchData();
- this._userData()
- }
- render() {
- return (
- <View >
- <Text>Welcome</Text>
- <ScrollView>
- {this.state.data.map((user, index) => {
- return (
- <View key={index} style={{ backgroundColor: '#abc123', padding: 10, margin: 10 }}>
- <Text style={{ color: '#fff', fontWeight: 'bold' }}>{user.name}</Text>
- <Text style={{ color: '#fff' }}>{user.password}</Text>
- </View>
- )
- })}
- </ScrollView>
- </View>
- );
- }
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- backgroundColor: '#F5FCFF',
- },
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement