相关疑难解决方法(0)

什么时候bindActionCreators会在react/redux中使用?

bindActionCreators的Redux文档声明:

唯一的用例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)
}
Run Code Online (Sandbox Code Playgroud)

VS

function mapStateToProps(state) {
  return {
    posts: state.posts,
    comments: state.comments
  }
}

function mapDispatchToProps(dispatch) {
  return {
    someCallback: (postId, index) => {
      dispatch({
        type: 'REMOVE_COMMENT',
        postId,
        index
      })
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

reactjs redux react-redux

81
推荐指数
4
解决办法
4万
查看次数

标签 统计

react-redux ×1

reactjs ×1

redux ×1