I used map
function for an array in states. I have gave them an index and I want to when they are clicked, Remove from the array. I have written the code below but It will remove all indexes except the item was clicked :)
This is my code :
removeFromList(x) {
this.setState({
allTasks: this.state.allTasks.splice(x, 1)
});
}
And :
this.state.allTasks.map((task, index) => {
return <li key={ index } onClick={ () => this.removeFromList(index) }>{ task }</li>;
})