this.props.navigation.dispatch 与 this.props.navigation.navigate 之间的区别? [英] Differences between this.props.navigation.dispatch vs this.props.navigation.navigate?
问题描述
我在 react-navigation 问题部分看到很多人使用 this.props.navigation.dispatch
以编程方式导航.是否有任何特定原因或用例在 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
?
似乎可以向 dispatch 函数传递更多选项?还有别的事吗?您可以在不将 react-navigation 明确绑定到您的应用程序 redux 存储中的情况下使用 dispatch 吗?现在我有一个带有 redux 的应用,但我没有明确配置我的 redux 设置来了解 react-navigation(如果可以的话,我更愿意保持这种方式).
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).
推荐答案
来自 React Navigation 文档的 Navigation Prop 章节 (https://reactnavigation.org/docs/navigators/navigation-prop#dispatch-Send-an-action-to-the-router):
From the React Navigation docs The Navigation Prop chapter (https://reactnavigation.org/docs/navigators/navigation-prop#dispatch-Send-an-action-to-the-router):
...其他导航功能在后台使用 dispatch...
...The other navigation functions use dispatch behind the scenes...
NavigationActions.navigate
和 this.props.navigation.navigate
的参数也是一样的.您使用哪一种应该没有区别.在我看来,this.props.navigation.navigate
更短,更易读.
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.props.navigation.dispatch 与 this.props.navigation.navigate 之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!