Using mobx store in react-navigation createStackNavigator

不想你离开。 提交于 2020-01-04 05:20:23

问题


I would like to use Mobx store variable in createStackNavigator in react-navigation. Specifically, I would like to change the initial route dynamically (so that user can change the initial screen) using the store. would this be possible? Something in the line of...

const stack = createStackNavigator({
Home:{
   ...
},
{
  initialRouteName: this.props.store.initialScreen
{
})

Because this is not a class, I cannot integrate mobx store. Any ideas to change the initialRoute dynamically is appreciated! Thanks


回答1:


You can have class-based StackNavigator this way:

class YourStack extends React.Component {
  render() {
    const { initialScreen } = this.props.store;

    const RouteConfigs = {
      //
    };

    const NavigatorConfigs = {
      initialRouteName: initialScreen,
    };

    const Stack = createStackNavigator(RouteConfigs, NavigatorConfigs);
    return <Stack />;
  }
}


来源:https://stackoverflow.com/questions/55551547/using-mobx-store-in-react-navigation-createstacknavigator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!