1
    class CreateMethod extends Component{

    constructor(props) {
        super(props);
      }

    addField(event) {
        console.log('checking',event);
    }
    submit(values){
      let owner = {
        "id": 1,
        "personClass": "EMP",
        "identityNumber": "11001"
      }
      values.owner = owner;
      values.linkedPhases =[]
      values.whoColumns = {};
      if(this.props){
      this.props.pMethodCreate(values);
      }
    }

    clear(){
        console.log('clearing the fields')
    }

    render(){
        // const {submit} = this.props
        console.log('the props are', this.props)
      return(
         <div className="users">
            <SearchSection
                options = {searbarInputs}
                onSubmit={this.submit}
                onClear={this.clear}
            />
            <ValueTable
                column2 = 'Method Details'
                column3 = 'Description'
                column1 = 'Seq No'
                option = { methodDesList }
                label = "Roles"
            />
                <SccButton />
            </div>
      )
   }
}

function mapDispatchToProps(dispatch){
    return bindActionCreators({ pMethodCreate }, dispatch)
}

function mapStateToProps(state){
    return {state}
}

export default connect(mapStateToProps, mapDispatchToProps)(CreateMethod)

and my reducer is :

import { MEATHOD_CREATE } from "../actions/methodAction";
export default function(state=[], action){
switch(action.type){
    case MEATHOD_CREATE :
        console.log('the result is', action.payload)
        return [...state, action.payload]
    default:
        return state;
}
return state;

and action is

    export function pMethodCreate(requestBody){
    return (dispatch)=> {
        return axios.post(url+'/save', requestBody).then(response => dispatch(methodCreation(response.data)));
    }
}

export function methodCreation(data){
    return {
        type:MEATHOD_CREATE,
        payload : data
    }
}

what I am doing wrong, I am trying to submitting the redux-form, I am kind of a newbie to this? I tried to do this by using redux docs but did not get good clarity. and if I am trying to dispatch any get request on componentDidMount() then it's working, don't know which piece of code is killing this?

  • 1
    The problem is how your methods are called vs. how they're bound. I've linked to a question that should answer this for you. – Mike Cluck Feb 08 '18 at 18:36
  • 1
    Hey thanks, @mike-c, I was not binding this to my function context. – Abhishek Kumar Pandey Feb 08 '18 at 18:41
  • i prefer to declare component functions using arrows functions instead of using the bind method. ie: submit = (values)=>{...}, i think its more readable and syntactically prettier. – Jay Lane Feb 08 '18 at 18:49

0 Answers0