简体   繁体   中英

React Native how to use passProps in NavigatorIOS component?

Here is my code:

<TouchableHighlight onPress = { () => {

    this.props.nav.push({
      component:  Movie,
      title: movie.title,
      passProps: {movie: movie},
    });

  }}>

When I press the button, the navigator transfers to a movie detail page ( Movie ), and when I do this.props.movie in the Movie component, it turns out that this.props is undefined. I know I am in the wrong way, so what is the correct way? Or other solution to pass property to the Movie component?

Any help will be appreciate! & Thanks in advance!

I assume movie is in your props scope? If so, then maybe you just need to scope it. Was movie.title getting passed through? Try this...

<TouchableHighlight onPress = { () => {

this.props.nav.push({
  component:  Movie,
  title: this.props.movie.title,
  passProps: {movie: this.props.movie},
});

}}>

Sorry guys, I've found the reason. It's not about where the movie data come from, but because I misunderstood the lifecycle of the component . I use this.props.movie in the getInitialState function of the Movie component which is apparently wrong.

Thanks for your help~

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