adrianhajdin / project_mern_memories

This is a code repository for the corresponding video tutorial. Using React, Node.js, Express & MongoDB you'll learn how to build a Full Stack MERN Application - from start to finish. The App is called "Memories" and it is a simple social media app that allows users to post interesting events that happened in their lives.
https://youtube.com/playlist?list=PL6QREj8te1P7VSwhrMf3D3Xt4V6_SRkhu
5.02k stars 1.84k forks source link

TypeError: Cannot read property 'find' of undefined #50

Open ghostship04 opened 3 years ago

ghostship04 commented 3 years ago

After updating the post the below error message gets displayed immediately even though the update was successful. The updated post can be seen once the page is refreshed. Version: Part_6

The error: C:/Users/project_mern_memories-PART_6/client/src/components/Posts/Post/Post.js:22

19 | const classes = useStyles(); 20 | 21 | const userId = user?.result.googleId || user?.result?._id;

22 | const hasLikedPost = post.likes.find((like) => like === userId); | ^ 23 | 24 | const handleLike = async () => { 25 | dispatch(likePost(post._id));

Could someone please help me with this issue?

VibhuGautam commented 3 years ago

Hey , I did this : const hasLikedPost = likes.find((like) => like === userId);

ghostship04 commented 3 years ago

It worked @VibhuGautam . Thank you so much.

mAlex28 commented 2 years ago

Thank you! this works

Hey , I did this : const hasLikedPost = likes.find((like) => like === userId);