Why do not output the variable 'resultado'?

Viewed 34

I want to print the variable resultado but I can't, do not mark a mistake, only I do not see it in my application. This is my code:

import React, {Component} from 'react';

import {View, Text, StyleSheet, Image, TextInput, Button, Alert} from 'react-native';

 export default class Login extends Component {

    constructor(props){
        super(props);
        this.state = {
            num1: "",
            num2:"",
            operacion:"",
            resultado:"",
        };
    }

    render(){
        const btnSumaClick = () => {
            let _this = this;
            this.state.operacion = "suma";
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    console.log(xhttp.responseText);
                    if ( xhttp.responseText ==='0'){
                        Alert.alert("Error","Favor de ingresar dos numeros", [{text: "Accept", onPress: () => console.log("alert closed")}]);
                    }else{
                        let recibe = xhttp.responseText;
                        _this.state.resultado = recibe;
                        console.log(_this.state.resultado);
                    }
             }
            };
            xhttp.open("GET", "https://proyecto150103.000webhostapp.com/Tarea1.php?num1="+this.state.num1 + "&num2="+ this.state.num2 + "&operacion=" + this.state.operacion, true);
            xhttp.send();
        }

        return(
            <View style={styles.container}>

                <Text style={styles.titulo}>Calculadora </Text>

                <TextInput style={styles.input}
                    placeholder="num1"
                    onChangeText={num1 => this.setState({num1})}
                />

                <TextInput style={styles.input}
                    placeholder="num2"
                    onChangeText={num2 => this.setState({num2})}
                />

                <View style={styles.btnSuma}>
                    <Button title="Suma" onPress={btnSumaClick}>
                    </Button>
                </View>

                <Text style={styles.titulo}> Resultado: {this.state.resultado} </Text> 

            </View>
        );
    }
}
const styles = StyleSheet.create({

    btnSuma:{
        width:100,
        height:80,
        marginLeft:150,
        marginTop:20,
    },

    input:{
        borderWidth:2,
        fontSize:25,
        margintTop:10,
        color: `#000000`, 
    },

    titulo:{
        fontSize:40,
        textAlign: "center",
        color: `#000000`, 
    },

    container:{
        backgroundColor: `#ffb6c1`,
    },


})

I do not know why i need to do :(

0 Answers
Related