0

I'm new to Redux and trying to figure out why the props throw an error when i have binded it with the matchDispatchToProps function. Shouldn't BindActionCreators already be binding the functions?

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);
teddybear123
  • 2,314
  • 6
  • 24
  • 38
  • Bind submit function to component instance – magnat Dec 14 '16 at 07:14
  • The error is thrown in the `submit` method which you are passing in ``. Nowhere elase are you referencing the `submit` method. That's not related to `matchDispatchToProps`,`bindActionCreators` or redux at all. – Felix Kling Dec 14 '16 at 07:39

0 Answers0