I'm new to React Native
, what I want to do is to get a this.state
of screen1 for example and use it on screen2 to print this same this.state
. I made a very grotesque example to try to explain:
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
TextInput,
TouchableHighlight,
} from 'react-native';
export default class Inputs extends Component {
constructor(props) {
super(props);
this.state = {
//Variáveis de entrada
num1: 0,
num2: 0,
//Variáveis que receberão resultados
resultadoSoma: 0,
};
this.calcularSoma = this.calcularSoma.bind(this);
}
//Cálculos
calcularSoma() {
let calculoSoma = 0;
calculoSoma = parseFloat(this.state.num1) + parseFloat(this.state.num2);
let s = this.state;
s.resultadoSoma = calculoSoma;
this.setState(s);
}
render() {
return (
<View>
<TextInput
onChangeText={num1 => {
this.setState({ num1 });
}}/>
<TextInput
onChangeText={num2 => {
this.setState({ num2 });
}}/>
<TouchableHighlight activeOpacity={0.3} onPress={this.calcularSoma}>
<Text style={styles.textoBotaoContinuar}>CALCULAR</Text>
</TouchableHighlight>
<Text>RESULTADO: {this.state.resultadoSoma}</Text>
</View>
);
}
}
How do I get this
<Text>RESULTADO: {this.state.resultadoSoma}</Text>
and show screen 2?
Any help will be of great value.