【问题标题】:Confusion about mapDispatchToProps关于 mapDispatchToProps 的困惑
【发布时间】:2021-02-11 17:20:13
【问题描述】:
const mapDispatchToProps = dispatch => ({
  locationUpdate: position => dispatch(locationUpdate(position)),
  groupFetch: city => dispatch(groupFetch(city)),
  groupFetchCoordinates: (location, selectedDistance) => dispatch(groupFetchCoordinates(location, selectedDistance))
})

我试图了解 mapDispatchToProps 与 react-redux 相关的内容,但偶然发现了这段代码。我查看了 mapDispatchToProps 上的文档,到目前为止,我所了解的是正在声明的函数(locationUpdate 和 groupFetch),它们本身会调用调度调用。我的困惑是,如果 mapDispatchToProps 是以如上所示的方式编写的,那么参数 'location 和 selectedDistance' 来自哪里?它只是一个声明,例如,如果您要调用这些方法,您可以只键入 groupFetch(city) 吗?请告诉我。谢谢。

【问题讨论】:

    标签: react-native redux react-redux


    【解决方案1】:

    这些是在你调用这些函数来调度它们时传入的参数:

    props.groupFetchCoordinates("San Francisco", 25)

    但是,请注意we now specifically recommend using the React-Redux hooks API as the default instead of connect

    【讨论】:

      猜你喜欢
      • 2019-05-17
      • 2020-03-06
      • 2016-03-16
      • 2013-07-27
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多