当我使用react-redux时,我想写下以下风格。
this.props.http.list()
this.props.http.detail()
this.props.http.create()
我应该如何将多个动作绑定到道具?
谢谢。答案 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