From ddbb40f532396367fc8676d5171619381056ec0f Mon Sep 17 00:00:00 2001 From: meet Date: Fri, 9 Aug 2024 15:24:09 +0530 Subject: [PATCH] Fixed fetch favorite post status code --- frontend/src/components/PostCard.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/PostCard.tsx b/frontend/src/components/PostCard.tsx index 2d830250..f3c8f444 100644 --- a/frontend/src/components/PostCard.tsx +++ b/frontend/src/components/PostCard.tsx @@ -42,6 +42,9 @@ const PostCard = ({ post, onDelete, currentUser }: Props) => { useEffect(() => { const fetchFavoriteStatus = async () => { try { + if (!currentUser) { + return; + } const token = localStorage.getItem("token"); if (!token) { return; @@ -56,9 +59,10 @@ const PostCard = ({ post, onDelete, currentUser }: Props) => { toast.error("Failed to fetch favorite status"); } }; - + fetchFavoriteStatus(); - }, [post.id]); + }, [post.id, currentUser]); + const handleAddToFavorite = async (event: React.MouseEvent) => { event.stopPropagation();