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

允我心安 提交于 2020-07-18 04:19:10

问题


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


回答1:


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.




回答2:


From github 👇🏻:

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



来源:https://stackoverflow.com/questions/43869903/differences-between-this-props-navigation-dispatch-vs-this-props-navigation-navi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!