【发布时间】:2017-10-21 21:21:39
【问题描述】:
我正在从屏幕 A 导航到屏幕 B.. 然后使用导航回到屏幕 A
this.props.navigation.goBack(null);
我想知道如何在执行此操作时传递参数?
这是我的代码
import React, { Component } from 'react';
import { View, Text, TextInput, ScrollView } from 'react-native';
import Card from './Card';
import CardSection from './CardSection';
import MyButton from './MyButton';
class Settings extends Component{
constructor(props){
super(props);
this.state = {
ip:'',
port:''
};
}
onSaveClick() {
console.log('Button clicked');
this.props.navigation.goBack();
}
render(){
const { input, container } = styles;
return(
<View style = {container}>
<Card>
<CardSection>
<TextInput
style = {input}
onChangeText = {(ip) => this.setState({ip})}
placeholder = "IP Address"
autoCapitalize = "none"
autoCorrect = {false}
keyboardType = "numeric"
/>
</CardSection>
<CardSection>
<TextInput
style={styles.input}
onChangeText={(port) => this.setState({port})}
placeholder="Port Number"
autoCapitalize="none"
autoCorrect={false}
keyboardType = "numeric"
/>
</CardSection>
<CardSection>
<MyButton onPress ={this.onSaveClick.bind(this)}>
Save
</MyButton>
</CardSection>
<View>
</View>
</Card>
</View>
);
}
}
那么我怎样才能在前一个组件中访问该组件的状态。我们可以将状态作为参数传递吗?
【问题讨论】:
标签: javascript react-native react-router react-navigation