mukeshphulwani66 / Instagram-clone-MERN-Stack

296 stars 212 forks source link

Issue with follow/unfollow #4

Closed Abbeyme1 closed 4 years ago

Abbeyme1 commented 4 years ago

I think the logic for follow and unfollow is incomplete as when we follow a user and then we refresh , we can follow that user again .

ACCORIDING TO ME WE CAN USE THIS LOGIC TO AVOID FOLLOWING THE SAME PERSON AGAIN AND AGAIN

useEffect(() => {
    user &&
      mainUser &&
      (user.user.followers.includes(mainUser._id)
        ? setShowFollow(false)
        : setShowFollow(true));
  }, [user]);