【问题标题】:How to access react navigation params outside react-native-drawer component如何在 react-native-drawer 组件之外访问反应导航参数
【发布时间】:2017-12-25 19:35:24
【问题描述】:

初始屏幕飞溅而不是导航到主屏幕和参数集。我想在侧边栏组件中获取参数。

const navigateActionHome = NavigationActions.navigate({
  routeName: 'drawerStack',
  action: NavigationActions.navigate({ 
        routeName: 'HomeScreen' , 
        params : { username : 'Testing' }
    })
})
this.props.navigation.dispatch(navigateActionHome)

// drawer stack
const DrawerStack = DrawerNavigator({
    Home: { screen: DashboardScreen },
    HomeScreen: { screen: HomeScreen }
},{
    contentOptions: {
      activeTintColor: "red"
    },
    gesturesEnabled: false,
    swipeEnabled: false,
    contentComponent: props => <SideBar {...props} />
});

我可以在 HomeScreen 组件中获取“用户名”参数,但无法在边栏组件中获取“用户名”参数。

【问题讨论】:

    标签: react-native redux react-navigation


    【解决方案1】:

    我相信当你在这里启动这个屏幕时:

    contentComponent: props => <SideBar {...props} />
    

    您传递的是屏幕的“道具”,而不是参数。那些不一样。您可以通过调试并在屏幕上的任何位置停止来确认您的屏幕是否有该道具。

    只要采取任何你在屏幕上获取用户名参数的方式,你就可以像这样添加它:

    contentComponent: props => <SideBar {...props} username={myUsername} />
    

    【讨论】:

    • 如何将数据从 API 推送到“myUsername”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-23
    • 2021-09-24
    • 2020-11-08
    • 1970-01-01
    相关资源
    最近更新 更多