我使用的是react navigation v4,在我建立的其他页面中,我使用navigation.navigate来发送param,当我试图在其他页面中做同样的事情时,我得到了未定义的值。
我想把这个值传递给
let VolunteerDest = documentSnapshot.data().delegation;
console.log('testing user delegation: ', VolunteerDest) // <~~~~~~~~~ its working ~~~~~~~~~~
this.props.navigation.navigate('Volunteer', {userDelegation: VolunteerDest});
在另一个页面上,我在compDidMount构造函数中试了一下......都没有用。
const id = this.props.navigation.getParam('userDelegation');
console.log('testing user delegation:' , id); // <~~~~~~~~~~~~~~ undefined
谁能告诉我这有什么问题吗?我读了导航文档,在这里和google上搜索,但找不到我的错误。
First Scrren :
<Button
title="Go Next"
//Button Title
onPress={() =>
navigate('SecondPage', {
JSON_ListView_Clicked_Item: this.state.username,
})
}/>
Second:
First Use this line
const { navigate } = this.props.navigation;
then after {this.props.navigation.state.params.JSON_ListView_Clicked_Item
? this.props.navigation.state.params.JSON_ListView_Clicked_Item
: 'No Value Passed'}
没有必要担心这个问题,你也可以像这样在状态下获取值。
this.state = {
subCatName: this.props.navigation.state.params.userDelegation
};