I've code something like,

constructor(props){
    super(props);
    this.state = {
        images: [],
    }
}

const tempImages = this.state.images;
tempImages.splice(index, 1);
this.setState({ images: tempImages });

were index will be dynamically come from table cell.

in the above code when I will try to remove the object from array it will not affect and not getting remove the element at that time after onwards state change it will set.

can someone please help me.

1 Answers

0
Community On Best Solutions

You can use lodash

import _ from "lodash";

const tempImages = _.cloneDeep(this.state.images);
tempImages.splice(index, 1);
this.setState({ images: tempImages });

it will help you to clone your entire object from state and update at the moment.