在react-navigation createStackNavigator中使用Mobx存储 [英] Using mobx store in react-navigation createStackNavigator
本文介绍了在react-navigation createStackNavigator中使用Mobx存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在react-navigation中的createStackNavigator中使用Mobx存储变量.具体来说,我想使用商店动态更改初始路线(以便用户可以更改初始屏幕).这有可能吗?符合...
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
{
})
因为这不是课程,所以我无法集成mobx存储.任何想法动态更改initialRoute表示赞赏!谢谢
Because this is not a class, I cannot integrate mobx store. Any ideas to change the initialRoute dynamically is appreciated! Thanks
推荐答案
您可以通过以下方式使用基于类的StackNavigator:
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 />;
}
}
这篇关于在react-navigation createStackNavigator中使用Mobx存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文