Advertisement
Guest User

Untitled

a guest
May 26th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import { StyleSheet, Text, View } from 'react-native';
  3.  
  4. export default class App extends React.Component {
  5.  
  6.   constructor(props) {
  7.     super(props);
  8.  
  9.     this.state = {
  10.       jsonData: [],
  11.       moneda: '',
  12.     }
  13.  
  14.   }
  15.  
  16.   componentDidMount() {
  17.  
  18.     return fetch('http://192.168.1.104:3000/dolar')
  19.       .then((response) => response.json())
  20.       .then((responseJson) => {
  21.         this.setState({
  22.           jsonData: responseJson
  23.         }, function() {
  24.           moneda = Object.keys(responseJson).map(function(key) {
  25.             var mone = responseJson[key];
  26.             console.log(mone);
  27.             if(mone = "USD"){
  28.               console.log(mone);
  29.               mone = key;
  30.               return "USD";
  31.             }
  32.             });
  33.           // In this block you can do something with new state.
  34.         });
  35.       })
  36.       .catch((error) => {
  37.         console.error(error);
  38.       });
  39.     }
  40.  
  41.  
  42.  
  43.   render() {
  44.     //console.log(this.state.jsonData);
  45.     console.log(this.state.moneda);
  46.     return (
  47.       <View style={styles.container} >
  48.         <Text>{this.state.jsonData.base}</Text>
  49.         <Text>{this.state.jsonData.date}</Text>
  50.         <Text>{this.state.moneda}</Text>
  51.  
  52.       </View>
  53.     );
  54.   }
  55. }
  56.  
  57. const styles = StyleSheet.create({
  58.   container: {
  59.     flex: 1,
  60.     backgroundColor: '#fff',
  61.     alignItems: 'center',
  62.     justifyContent: 'center',
  63.   },
  64. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement