In my sample todo app, I have created a list of todo items that are stored in an array. In my wrapper List class I render the elements as Items in the array, I have a remove function that I pass as props to the Items and once the items are clicked, they are removed from the array and thus not rendered anymore. The problem that I am having is that when I remove the first element of the array, the second moves up, but the state of the second Item element is set to the state of the deleted first element even when the props of the element are correct.
This is my List element
<div className="tasks-wrap">
{this.state.items.map((task, index) => {
return (
<Item index={index} refreshColor={this.state.refreshColor} ref={this.child} key={index} item={task} remove={this.remove}/>
)})}
</div>
And this is the constructor of the item element
constructor(props) {
super(props);
console.log(this.props.index)
this.state = {dateDue:this.props.item.dateDue, urgency_class:this.refreshColor()};
this.refreshColor = this.refreshColor.bind(this)
}
Why is this happening?