如何在react native中正确使用导航中的getparam?

问题描述 投票:0回答:1

我使用的是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上搜索,但找不到我的错误。

react-native react-navigation
1个回答
0
投票
    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'}

0
投票

没有必要担心这个问题,你也可以像这样在状态下获取值。

this.state = {
        subCatName: this.props.navigation.state.params.userDelegation
    };
© www.soinside.com 2019 - 2024. All rights reserved.