don't add to array if item id exists react code example
Example: react array if id is present do not add element
addPerson = (person) => {
let filteredPerson = this.state.likes.filter(like => like.name !== person.name);
this.setState({
likes: [...filteredPerson, person]
})
}