i am trying to print value of variable 'str' by setting its state. My approach is When the user click the button Print the TextInput value in the Text field. I am getting the value though using console and alert but its not printing in the desired tags
Here's my code
`
var str="";
class WeatherProject extends Component{
constructor (props) {
super(props);
this.state={
From:'',
To:''
}
}
changeText=(From)=>{
this.setState({From})
}
onPress = ()=>{
str= this.state.From
}
render(){
return (
<View>
<TextInput placeholder="From" id="from" style={styles.fromField} onChangeText={this.changeText} />
<Button
title={"Press"}
color="#f194ff"
onPress={this.onPress}
></Button>
<Text>{str}</Text> //Here i need the output via variable str
</View>
);
}
}
export default WeatherProject
`
onPress = ()=>{this.setState({To: this.state.From})}and<Text>{this.state.To}</Text>