我是Redux的新手,并试图弄清楚当我用matchDispatchToProps函数绑定它时道具抛出错误的原因。 BindActionCreators不应该绑定函数吗?
import ContactForm from '../containers/ContactForm';
import React, { Component } from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {handleSubmit} from '../actions/index'
class ContactPage extends Component {
submit(values) {
this.props.handleSubmit(values) //ERROR
}
render() {
return (
<ContactForm onSubmit={this.submit} />
);
}
}
function mapStateToProps(state) {
return {
contacts: state.users
};
}
// Get actions and pass them as props to to UserList
// > now UserList has this.props.selectUser
function matchDispatchToProps(dispatch){
return bindActionCreators({handleSubmit: handleSubmit}, dispatch);
}
// We don't want to return the plain UserList (component) anymore, we want to return the smart Container
// > UserList is now aware of state and actions
export default connect(mapStateToProps, matchDispatchToProps)(ContactPage);