Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import { StyleSheet, Text, View } from 'react-native';
- export default class App extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- jsonData: [],
- moneda: '',
- }
- }
- componentDidMount() {
- return fetch('http://192.168.1.104:3000/dolar')
- .then((response) => response.json())
- .then((responseJson) => {
- this.setState({
- jsonData: responseJson
- }, function() {
- moneda = Object.keys(responseJson).map(function(key) {
- var mone = responseJson[key];
- console.log(mone);
- if(mone = "USD"){
- console.log(mone);
- mone = key;
- return "USD";
- }
- });
- // In this block you can do something with new state.
- });
- })
- .catch((error) => {
- console.error(error);
- });
- }
- render() {
- //console.log(this.state.jsonData);
- console.log(this.state.moneda);
- return (
- <View style={styles.container} >
- <Text>{this.state.jsonData.base}</Text>
- <Text>{this.state.jsonData.date}</Text>
- <Text>{this.state.moneda}</Text>
- </View>
- );
- }
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: '#fff',
- alignItems: 'center',
- justifyContent: 'center',
- },
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement