Skip to content

Instantly share code, notes, and snippets.

@shubhnik
Last active November 10, 2017 17:10
Show Gist options
  • Save shubhnik/d5c76c81b5ef0437e918738451970259 to your computer and use it in GitHub Desktop.
Save shubhnik/d5c76c81b5ef0437e918738451970259 to your computer and use it in GitHub Desktop.
Demonstration code on passing our own navigation prop (containing state calculated from navigationReducer and redux's dispatch) to the navigator(AppNavigator)
// our basic navigationReducer which will feed AppNavigator with navigation state ---> https://gist.github.com/shubhnik/b55602633aaeb5919f6f3c15552d1802
// Don not forget to check the complete code here ---> https://github.com/shubhnik/redux-react-navigation
const AppNavigator = StackNavigator({
screen1: {
screen: Screen1
},
screen2: {
screen: Screen2
}
});
class AppNavigation extends Component {
render() {
const { navigationState, dispatch } = this.props;
return(
<NavigationStack
navigation={addNavigationHelpers({ dispatch, state: navigationState })} // passing our navigation prop (consisting of dispatch and state) to AppNavigator.
/>
)
}
}
const mapStateToProps = (state) => {
return ({
navigationState: state.NavigationReducer // NavigationReducer contains the navigation state of the app
})
}
export default connect(mapStateToProps)(AppNavigation)
@yonahforst
Copy link

yonahforst commented Nov 10, 2017

hey! i think you mean to use AppNavigator on line 16, right? Great write up btw! perfect timing, i was just pulling my beard our trying to understand how the navigator integrates with redux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment