如何将多个动作绑定到一个props对象挂载点

时间:2016-12-25 17:14:41

标签: reactjs redux react-redux

当我使用react-redux时,我想写下以下风格。

this.props.http.list()
this.props.http.detail()
this.props.http.create()

我应该如何将多个动作绑定到道具?

谢谢。

1 个答案:

答案 0 :(得分:0)

如上所述here

import * as todoActionCreators from './todoActionCreators'
import * as counterActionCreators from './counterActionCreators'
import { bindActionCreators } from 'redux'

function mapStateToProps(state) {
  return { todos: state.todos }
}

function mapDispatchToProps(dispatch) {
  return bindActionCreators(Object.assign({}, todoActionCreators, counterActionCreators), dispatch)
}

export default connect(mapStateToProps, mapDispatchToProps)(TodoApp)

使用mapDispatchToProps将组件功能与redux

中的action creator绑定