我通过反向导航发送参数。从屏幕 B 到 A. 但是当我控制台 this.props.route.params.value 然后我得到未定义的错误。请帮忙。我怎样才能得到我向后发送的数据。我不知道redux。有没有没有redux的快速方法。
这里是屏幕A
import { TouchableOpacity, View } from "react-native";
export default class patientReadings extends Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
console.log(this.props.route.params.value)
return (
<View>
<TouchableOpacity
onPress={() => this.props.navigation.navigate("B",{value1:"1"})}
>
button 1
</TouchableOpacity>
<TouchableOpacity
onPress={() => this.props.navigation.navigate("B",{value2:"2"})}
>
button 2
</TouchableOpacity>
<TouchableOpacity
onPress={() => this.props.navigation.navigate("B",{value3:"3"})}
>
button 3
</TouchableOpacity>
</View>
);
}
}
这里是屏幕 B
export default class medicalInput extends React.Component {
constructor(props) {
super(props);
this.myRef = React.createRef();
this.state = {};
}
validateInputs = (event) => {
fetch("api", {
method: "POST",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
},
body: JSON.stringify([
{
data,
},
]),
})
.then((returnValue) => returnValue.json())
.then((response) => {
console.log(response);
this.props.navigation.navigate("A", {value : this.props.route.params.value1+"1"});
});
};
render() {
return (
<TouchableOpacity
onPress={() => this.validateInputs()}
></TouchableOpacity>
);
}
}