bindActionCreators个州的Redux份文件:
bindActionCreators
的唯一使用 case 是,当您想将一些动作创建者传递给一个不知道Redux的组件,并且不想将dispatch或Redux store传递给它时.
如果使用/需要bindActionCreators
个,会是什么样的例子?
哪种组件不知道Redux?
两种 Select 的优缺点是什么?
//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
})
}
}
}