I am getting an array of posts data from a server, and then i am mapping over it. Inside each post there is an array of IDs of users who liked the post. I am trying to tell the user if it liked the post already:
{!postLikes.some((didLike) => didLike._id === currentUser) ? (---DidNotLike---) : (---Liked---)
The idea is, if the user did not like the post, and likes it after the post has loaded, the ternary expression works, but the first time it renders it does not work. I checked with console logs that the array is in fact loaded in time and that the currentUser ID matches a value from the array.
If i use
{postLikes.includes(currentUser) === true && (---Liked---)}
then when posts render for the first time, it shows which posts the user liked, but it does not give feedback when it likes others (until re-render). What could be the cause?