我正在尝试达到我从父组件发送的token
参数:
import React, { Component } from "react";
import {
SafeAreaView,
ScrollView,
View,
Image,
Text,
ImageBackground,
} from "react-native";
import firebase from "firebase";
import CustomDrawerMenu from "./CustomDrawerMenu";
class CustomDrawer extends Component {
constructor(props) {
super(props);
this.user = firebase.auth().currentUser;
}
render() {
return (
<SafeAreaView style={{ flex: 1 }}>
<View
style={{
height: 150,
backgroudColor: "white",
}}
>
<ImageBackground
source={require("../assets/bg.jpeg")}
style={{
width: "100%",
height: "100%",
justifyContent: "center",
alignItems: "center",
}}
>
<Image
source={require("../assets/profile.png")}
style={{
width: 100,
height: 100,
borderRadius: 60,
borderColor: "white",
borderWidth: 4,
}}
/>
<Text style={{ color: "white", marginTop: 10 }}>
{this.user ? this.user.email : ""}
</Text>
</ImageBackground>
</View>
<ScrollView>
<CustomDrawerMenu {...this.props} token={new Date()} />
</ScrollView>
</SafeAreaView>
);
}
}
export default CustomDrawer;
在customDrawerMenu
中,我尝试使用this.props.navigation.getParam("token")
检索令牌,但抛出错误。在这里,我试图达到它:
class CustomDrawerMenu extends Component {
constructor(props) {
super(props);
}
componentDidUpdate() {
const currToken = this.props.navigation.getParam("token");
if (currToken != this.lastToken) {
this.lastToken = currToken;
this.setState({ token: this.lastToken });
}
}
.....
}
这是错误:
this.props.navigation.getParam is not a function. (In 'this.props.navigation.getParam("token")', 'this.props.navigation.getParam' is undefined)
答案 0 :(得分:0)
您在道具中传递了令牌
<CustomDrawerMenu {...this.props} token={new Date()} />
那么,为什么它应该放在this.props.navigation中?
它在this.props.token