Trying to avoid a duplicate question but I think this varies from the previous ones I searched for.
I have a state of 'favorites' that is an array of items. I want to add an item to the array in the following function. I'm creating a variable that has the value of the favorites, then pushing the new value into that variable of arrays and setting the favorite state to the new variable.
This is working for me but I am trying to see if it's an improper way to do it.
handleAddFavorite(item) {
let favorites = this.state.favorites;
favorites.push(item);
this.setState({
favorites: favorites
});
}