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 how to update the current view.
export default () => <MyTabNav
ref={(ref) => { this.nav = ref; }}
onNavigationStateChange={(prevState, currentState) => {
//call function on current view
}}
/>;
There's some long discussions about this from react-native issue 314, 486, 1335, and finally we got a better built in way to handle this, after Sep 27, 2017, react-navigation version v1.0.0-beta.13:
Usage:
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.
Actually, you can add an special listener in your component