【发布时间】:2017-06-04 21:38:22
【问题描述】:
Redux 文档 bindActionCreators 声明:
bindActionCreators的唯一用例是当您想将一些操作创建者传递给不了解 Redux 的组件,并且您不想将调度或 Redux 存储传递给它时。
使用/需要bindActionCreators 的示例是什么?
哪种组件不知道Redux?
这两种选择的优缺点是什么?
//actionCreator
import * as actionCreators from './actionCreators'
function mapStateToProps(state) {
return {
posts: state.posts,
comments: state.comments
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(actionCreators, dispatch)
}
vs
function mapStateToProps(state) {
return {
posts: state.posts,
comments: state.comments
}
}
function mapDispatchToProps(dispatch) {
return {
someCallback: (postId, index) => {
dispatch({
type: 'REMOVE_COMMENT',
postId,
index
})
}
}
}
【问题讨论】:
标签: reactjs redux react-redux