问题
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