在无状态的tabNavigator中的initialRouteName中使用redux

时间:2019-05-20 14:18:26

标签: reactjs redux native

我想在differnetnet用户登录时更改选项卡。我正在使用redux来获取用户类型(该数字是:0或大于0的数字),但是当我尝试使用this.props.id时出现错误:“未捕获的错误:未定义不是对象(正在评估'this.props.id')。

function mapStateToProps(state) {
  return {
    id: state.usert
  };
}

const HomeStack = createStackNavigator(
  {
    LogIn: LogIn,
    Home: PlayersList,
    Player: PlayerPage,
    Week: Calendar,
    Stat: PlayerStatistic,
    Goal: PlayerGoals,
    Group: GroupStatistic,
    PlayerPPage: PlayerPlayerPage
  },
  {
    mode: "card"
  });

const CoursesStack = createStackNavigator(
  {
    Courses: PlayerGoals,
    Goals: GroupStatistic,
  },
  {
    initialRouteName: this.props.id === 0 ? "Courses" : "Goals"
  }
);



const TabNavigator = createBottomTabNavigator({
  HomeStack,
  CoursesStack,
});

export default connect(mapStateToProps)(TabNavigator);

0 个答案:

没有答案