I see a lot of folks in the react-navigation issues section using this.props.navigation.dispatch
to programmatically navigate. Is there any specific reason or use case to use that over this.props.navigation.navigate
?
It seems like you can pass more options to the dispatch function? Is there anything else? Can you use dispatch without explicitly tying react-navigation into your apps redux store? Right now I have an app that has redux, but I dont explicitly configure my redux setup to know about react-navigation (and would prefer to keep it that way if I can).
The dispatch method lets us send a navigation action object which determines how the navigation state will be updated. All of the navigation functions like navigate use dispatch behind the scenes.
Each navigation is a React component that is implicitly returned. Various styles and configurations can be applied to the components. We wrap the screens provided to us from the instance of the tab navigation defined above in a navigator component, and define the styles using the tabBarOptions props.
option - replace Normally a call to navigate will push a new entry into the history stack so the user can click the back button to get back to the page. If you pass replace: true to navigate then the current entry in the history stack will be replaced with the new one.
From the React Navigation docs The Navigation Prop chapter (https://reactnavigation.org/docs/navigators/navigation-prop#dispatch-Send-an-action-to-the-router):
...The other navigation functions use dispatch behind the scenes...
Also parameters for NavigationActions.navigate
and this.props.navigation.navigate
are the same. There should be no difference which one you use. In my opinion, this.props.navigation.navigate
is shorter and more readable.
This is the code of navigate
function which reuses navigation.dispatch
.. And remember:
Code Don't Lie
Then, navigation.navigate(...args)
is an alias of navigation.dispatch(NavigationActions.navigate(...args))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With