Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between this.props.navigation.dispatch vs this.props.navigation.navigate?

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).

like image 598
arcom Avatar asked May 09 '17 12:05

arcom


People also ask

What does navigation dispatch do?

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.

What is the type of navigation in react navigation?

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.

What is navigate replace?

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.


2 Answers

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.

like image 152
saschbro Avatar answered Oct 18 '22 15:10

saschbro


From github 👇🏻:

enter image description here

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))

like image 31
Abdennour TOUMI Avatar answered Oct 18 '22 15:10

Abdennour TOUMI