I would like to conditionally add something to an array using a spread operator if it matches a particular condition (ie. if the movie id does not match other movie id’s that already exist in my array)
case ADD_FAVORITE:
return {
...state,
favorites: [ state.favorites !== action.payload.id? ...state.favorites, action.payload]
}
This is what I have tried
action payload returns something like this
{id: 0, title: 'The Godfather', director: 'Francis Ford Coppola', metascore: 100, genre: 'Drama', …}
and inside state.favorites:
description: "Luke Skywalker joins forces with a Jedi Knight, a cocky pilot, a Wookiee and two droids to save the galaxy from the Empire's world-destroying battle station, while also attempting to rescue Princess Leia from the mysterious Darth Vader."
director: "George Lucas"
genre: "Scifi"
id: 1
metascore: 92
title: "Star Wars"
[[Prototype]]: Object