Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29639

Is this the correct way of removing an item from a array in React Native?

$
0
0

I'm implementing a To-Do list in React Native, but for some reason after I remove a task, the next task in the array takes some values of the one I removed. I made a copy of the state array and made changes to it, console.log them to see that everything was right, then setState with that copy. I think it must be an issue with the sate. Here is simplified version of my remove_task function. Am I doing something wrong?

 _removeTask = (tindex) => {
/*removes a task in the tasks array*/
//make copy of state array
var tasks = [...this.state.Tasks];

var taskCount = 0;

tasks.splice(tIndex, 1);

//update the index of every quest
tasks.forEach(
  (value, index) => {
    value.tIndex = index;
    value.selected = false;
    value.isActiveDummyTask = false;
    value.isInEditMode = false;
    taskCount++;
  }
)
this.setState({ 
  Tasks: tasks,
  TCount: taskCount,
});

}


Viewing all articles
Browse latest Browse all 29639


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>