The React setStats array is not updated, which makes it hard to understand.

the building encountered a tricky problem today.
is that this.setStats ({}) does not update this.stats.
the problem is
constructor (props) {

.
    super(props);
    this.state = {
        imageList: []
    }

    WechatService.getMaterialOrealList("image").then((result) => {
        this.setState({
            imageList: result
        })
    });

}

 async handleInputChangeUpload(event) {
    var target = event.target;
    var file = target.files[0];

    var formData = new FormData();
    formData.append("file", file);

    var result = await WechatService.updateMaterialImage(formData);

    var lists = this.state.imageList;
    lists.push(result);
    console.log(lists);
    //
    this.setState((prevState, props) => ({
        imageList: lists
    }))

}


11 render

this.setState((prevState, props) => ({


elementsUI
constructor(props) {


}

componentWillMount() {


}

handleUpload() {


}

async handleInputChangeUpload(event) {


}


Why is this?
cannot answer

author: silly Dream
Link: https://juejin.im/post/5b1a22.
Source: Nuggets
copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please indicate the source.

Mar.18,2021

  

setstate only make shallow comparisons

Menu