getting error: Cannot read property state of undefined

前端 未结 3 2066
生来不讨喜
生来不讨喜 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:30

    there is no state in constructor yet

    if you want to set state in constructor you can do it like this

    class SomeComponent extends Component {
       constructor(props){
          super(props)
    
          this.state = { ... }
       }
    }
    

    or even like this

    class SomeComponent extends Component {
    
       state = {  }
    
    }
    

    but in this case babel should be properly configured

提交回复
热议问题