On the problem of data assignment

in state in react, declare this:

constructor (props) {

super(props);
this.state = {
  get leftCover() {
    let index = 0;
    let data =undefined;
    
    data={  //
      "img": props.list[index].img,
      "status": props.list[index].status,
      "title": props.list[index].title,
      "subTitle": props.list[index].subTitle,
      "index": props.list[index].index
    }
  }
};

}

screenshot of error report:

Mar.10,2021

you need to send data return out, otherwise: state.leftCover is undefined .

 

those attributes cannot be placed directly on the component , and some of them are not legal.

it's already stated in the error message. If you want to customize the property, put data-* to do it

that's not the problem, but when you use these state

Menu