I'm setting up an app that uses react-native-navigation
. There are some values I'd like to persist across navigation. When I manully trigger navigation, I can pass these as parameters in the call to navigate
. But when I use native navigation provided by the plug-in, I'm not able to set this as a parameter.
What would be the best way to share an API token across my entire application, without the necessity to store it in AsyncStorage? Am I missing some obvious solution?
My App.js:
const AppStack = createBottomTabNavigator({
Members: createStackNavigator({
MemberList: MemberList,
AddMember: NewMember,
},{
mode: 'card',
initialRouteName: "MemberList"
}),
Scan: Scanner
});
const AuthStack = createStackNavigator({ Login: Login });
export default createAppContainer(
createSwitchNavigator(
{
AuthLoading: AuthLoadingScreen,
App: AppStack,
Auth: AuthStack
},
{
initialRouteName: "AuthLoading"
}
)
);
The Auth stack is taking care of the authentication, after the API token is acquired, I manually reroute to the App using this approach:
this.props.navigation.navigate({
routeName: 'App',
params: { auth_token: data.auth_token },
action: this.props.navigation.navigate({
routeName: 'MemberList',
params: { auth_token: data.auth_token}
})
});
The problem occurs when I start navigating with the bottom Nav, because this is dealt with by the plugin, there seems to be no persisted parameters.