react-navigation icon indicating copy to clipboard operation
react-navigation copied to clipboard

NavigationActions and Redux Integration

Open nprz opened this issue 9 years ago • 2 comments

I noticed in the ReduxExample (which I was unable to get running) on line 25 of AuthButton.js an action is set up to dispatch like so.

loginScreen: () => dispatch(NavigationActions.navigate({ routeName: 'Login' }))

However this action does not make sense. Since the action being dispatched is of type Navigation/NAVIGATE, this will not result in the state changing since the reducer is not listening for a Navigation/NAVIGATE action. Why is this in the example? Who is listening for this dispatched action and how does it change the state if the reducer is not listening for it?

Thanks.

nprz avatar May 19 '17 21:05 nprz

I believe this action will fall through to the default branch of the switch statement in the nav reducer. The call to AppNavigator.router.getStateForAction(action, state) will produce the new nav state.

https://github.com/react-community/react-navigation/blob/master/examples/ReduxExample/src/reducers/index.js#L31

willmcneilly avatar May 20 '17 21:05 willmcneilly

Ah, that makes sense. Thank you!

nprz avatar May 22 '17 14:05 nprz