My current state has this:
state = { items : [{id: 1, text: 'test words'}, {id: 2, text: 'another test'}]
Here's my function to remove objects from the array, trying to avoid mutating state.
handleRemove(passedInId) {
const myItems = this.state.items
const newArray = myItems.filter(item => item.id !== passedInId)
this.setState(prevState => ({
items: prevState.items = newArray
}))
console.log('handle remove runned', passedInId, myItems, newArray)
}
It works perfectly but would like to know if it's not anti-pattern before moving on with my life
Many THANKS!!