Pass value between component in React Native Navigator

前端 未结 6 2036
后悔当初
后悔当初 2020-12-03 10:37

How can I pass data from sceneA to sceneB with Navigator in React Native?

I\'m using this to go to sceneB:



        
6条回答
  •  庸人自扰
    2020-12-03 11:07

    Sometimes the pass prop doesn't work (at least for me) So what I do is I pass it in the route object itself

    nav.push({
            id: 'MainPage',
            name: 'LALA',
            token: tok
          });
    

    so to access it in the next scene I use

    var token = this.props.navigator.navigationContext.currentRoute.token;
    

    although kind of a complicated "access" but it is fool proof pass props might work or might not also in this way you can pass the properties in the route object itself thus saving you from the hassle of sending it in a different way.

    This might not be the right way but I find it a tad bit more convenient.

提交回复
热议问题