#einKnuffy

1 messages · Page 1 of 1 (latest)

hollow isle
#

Hey, I don’t know if this will help, your problem could be something much deeper than what I’m going to say here.

#

You’re using the _id, so I assume you’re using MongoDB

#

The IDs are probably ObjectIds and the only way to check if they’re equal is by using the equals method on the ObjectId or converting both to strings and checking if they’re equal there

#

If you’re sure the IDs aren’t ObjectIds, I don’t know how else it won’t change as you add an remove it from the array

#

Maybe the variable isn’t a state and isn’t triggering your component to re-render

#

But if it’s a state and an ObejctId, you should do something like this

#

With Array.find

#

user.favorites.find(favoriteId => favoriteId.equals(item._id)) ? SYMBOL_1 : SYMBOL_2

#

user.favorites.find(favoriteId => String(item._id) === String(favoriteId)) ? SYMBOL_1 : SYMBOL_2

#

That’s how I see the error being solved