反应本机 TabNavigator 导航参数 [英] React native TabNavigator navigation params

查看:43
本文介绍了反应本机 TabNavigator 导航参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过主屏幕中的按钮单击操作将路由参数发送到配置文件选项卡.下面的代码是标签导航器

I want to send route params to Profile tab from button click action in Home screen. Below code is tab navigator

  const Tabs = TabNavigator({
  [routes.HOME]: {
    screen: FeedMainScreen,
    navigationOptions: {
      tabBarLabel: tabBarLabels.HOME_TAB_LABEL,
    },
  },
  [routes.SEARCH]: {
    screen: SearchScreen,
    navigationOptions: {
      tabBarLabel: tabBarLabels.SEARCH_TAB_LABEL,
    },
  },
  [routes.PROFILE]: {
    screen: ProfileScreen,
    navigationOptions: {
      tabBarLabel: tabBarLabels.PROFILE_TAB_LABEL,
    },
  },

}

和按钮点击导航是这样的

and button click navigation is like this

<Button onPress={() => this.props.navigation.navigate(routes.PROFILE, { id: this.props.user._id }, null)} />

并像这样从个人资料屏幕访问参数

and accsess param from Profile screen like this

constructor (props) {
 super(props)
 console.log('NavPrams', this.props.navigation.state)
}

始终未定义

推荐答案

您可以使用 connect() 方法成功映射 props 并在任何地方使用它们.在编写的类中添加下面提到的代码 -

You can use connect() method to successfully map the props and use them anywhere. Add the below mentioned code in the class where is written -

    const mapStateToProps = state => {
    return {
        user: this.props.user;
    };
};
export default connect(mapStateToProps, {})(className);

这篇关于反应本机 TabNavigator 导航参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆