简体   繁体   中英

How to pass props between 2 scene in NavigationExperimental React Native using Redux

i am using Naviagtion Experimental and i have a listview, when user select item on listview i will open item detail by using push of Navigation Experimental. I have a issue How to pass props between 2 scene in NavigationExperimental React Native using Redux ? (i am using android)

Thanks.

The easiest way is to send props using the route object that you already use for navigation.

In your ListView

const route = {key: 'detail', itemId: 123}
<TouchableHighlight
  onPress={() => handleNavigate({type: 'push', route: route}) >
...
</TouchableHighlight>

And in your NavigationCardStack 's renderScene , you can pass in the props to your detail view component

renderScene(props) {
  const {route} = props.scene
  ...
  if (route.key === 'detail') {
    return <DetailViewComponent
      goBack={...}
      itemId={route.itemId} />
  }
}

I would recommend you to use react-native-router-flux.

You can get it from here : https://github.com/aksonov/react-native-router-flux

It's very easy to pass props with that. for example navigating to component X and passing props :

 Actions.X({testProps: 'hello', title: 'Page titile'}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM