1
Guys, I’m new to React Native
, what I want to do is catch a this.state
from screen 1 for example and use it on screen 2 to print that 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 = {
num1: 0,
num2: 0,
resultadoSoma: 0,
};
this.calcularSoma = this.calcularSoma.bind(this);
}
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 catch this
<Text>RESULTADO: {this.state.resultadoSoma}</Text>
and show you screen 2?
Any help will be of great value.
I was able to pass the values from one screen to another using this React-Native-navigation feature. Thank you very much :D
– Caio Mantovani