How to Pass Parameters to screen in StackNavigator?

后端 未结 6 1369
抹茶落季
抹茶落季 2020-12-13 05:46

My React Native code:

import React, { Component } from \'react\';
import { AppRegistry, ActivityIndicator, StyleSheet, ListView, 
  Text, Button, TouchableH         


        
6条回答
  •  天涯浪人
    2020-12-13 06:51

    You can pass params with the navigate function's second argument:

    onPress(user) {
      this.props.navigation.navigate(
        'DetailPage',
        { user },
      );
    }
    

    React Navigation 5.x (2020)

    Access them in this.props.route.params. For example in your DetailsPage:

    {this.props.route.params.user.name}
    

    https://reactnavigation.org/docs/params/

    React Navigation <= 4.x

    Access them in this.props.navigation.state.params. For example in your DetailsPage:

    {this.props.navigation.state.params.user.name}
    

    https://reactnavigation.org/docs/4.x/params/

提交回复
热议问题