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(城市)?请让我知道。谢谢。
发布于 2021-02-12 01:25:55
这些是您在调用这些函数以分派它们时传入的参数:
props.groupFetchCoordinates("San Francisco", 25)
但是,请注意we now specifically recommend using the React-Redux hooks API as the default instead of connect。
https://stackoverflow.com/questions/66159592
复制相似问题