I'm trying to develop a web app using React Js
, but I've run into a problem, which I do not understand why it happens.
What is enclosed in the red colored rectangle is a component, and what is enclosed with the green color is another. I perform the following procedure, in order to execute a function.
The ideal is to be able to obtain the information, both from the request that I make to google maps , sending an address, or entering by keyboard the other information in the other component .
Order
false
to true
false
to true
true
, the function is executed, but the data of the object that relates to the text boxes on the right, which update, are always empty. Parent component code
import React, { Component } from 'react';
import { render } from 'react-dom';
import AddressInput from './components/address.js';
import InputDataPerson from './components/dataPersonHouse.js';
import TableConsumeInformation from './components/tableInformation.js';
import './styles/main.css';
class App extends Component{
constructor(){
super();
this.state = {
geoInfo:{
Latitude:"",
Longitude:""
},
dataInfoHouse:{
year:"",
anguloInclinacion: "",
potenciaPaneles: "",
diasNoSoleados: ""
},
activate:{
adress: false,
dataHouse: false
}
};
this.updateGeoInfo = this.updateGeoInfo.bind(this);
this.updateInfoHouse = this.updateInfoHouse.bind(this);
}
render(){
return(
<div>
<div className="Contenedor">
<div className="Espacio">
<AddressInput newInfo={this.updateGeoInfo}/>
</div>
<div className="Espacio">
<InputDataPerson newInfo={this.updateInfoHouse}/>
</div>
</div>
<div>
<TableConsumeInformation ref={instance => { this.tableInformation = instance; }}/>
</div>
</div>
)
}
updateGeoInfo(geoData){
let geoInfo = Object.assign({}, this.state.geoInfo);
let activate = Object.assign({}, this.state.activate);
let infoNASARequest = {
dataHome:"",
dataGeo:""
};
geoInfo.Latitude = geoData.ltd;
geoInfo.Longitude = geoData.lng;
this.setState({geoInfo});
activate.adress = true;
this.setState({activate});
if(activate.adress == true && activate.dataHouse == true){
console.log("ambas posicion geo");
this.sendInfoNasaRequest();
}
}
updateInfoHouse(dataHouse){
let infoHouse = Object.assign({}, this.state.dataInfoHouse);
let activate = Object.assign({}, this.state.activate);
let infoNASARequest = {
dataHome:"",
dataGeo:""
};
infoHouse.year = dataHouse.year;
infoHouse.potenciaPaneles = dataHouse.potenciaPanel;
infoHouse.diasNoSoleados = dataHouse.diasNoSoleados;
infoHouse.anguloInclinacion = dataHouse.anguloInclinacion;
this.setState({infoHouse});
activate.dataHouse = true;
this.setState({activate});
if(activate.adress == true && activate.dataHouse == true){
console.log("ambas en informacion de la casa");
this.sendInfoNasaRequest();
}
}
sendInfoNasaRequest(){
let infoNASARequest = {
dataGeo:this.state.geoInfo,
dataHome:this.state.dataInfoHouse
};
this.tableInformation.CalculateRadiation(infoNASARequest);
}
}
export default App;
Note: The values of the object I keep in dataHome
are always empty.