getting error: Cannot read property state of undefined

前端 未结 3 2085
生来不讨喜
生来不讨喜 2020-11-28 15:42
import React, { Component } from \"react\";
import FormUpdate from \"../components/formUpdate\";
import { fetchClothingItem, updateClothingItem } from \"../actions/c         


        
3条回答
  •  日久生厌
    2020-11-28 16:34

    You forgot to bind your handleSubmit function to the class. You can either use arrow function to define the function.

    handleSubmit=(data) =>{
    ...
    }
    

    Or you can bind the function in your constructor.

    constructor(props) {
            super(props);
            this.state = {
              updateClothingItem: {}
            };
            this.handleSubmit= this.handleSubmit.bind(this,data);
        }
    

提交回复
热议问题