Without using Redux, how do I detect a tab change with a react navigation tab navigator?
I know I need to somehow use onNavigationStateChange but I can\'t figure out
export default () => { this.nav = ref; }}
onNavigationStateChange={(prevState, currentState) => {
const getCurrentRouteName = (navigationState) => {
if (!navigationState) return null;
const route = navigationState.routes[navigationState.index];
if (route.routes) return getCurrentRouteName(route);
return route.routeName;
};
global.currentRoute = getCurrentRouteName(currentState);
}}
/>;
If you don't want to use redux, this is how you can store global information about the current route, so you can both detect a tab change and also tell which tab is now active.