无法读取未定义的属性'props',React-Redux

时间:2016-12-14 07:11:22

标签: reactjs ecmascript-6 redux

我是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);

0 个答案:

没有答案
相关问题