project_mern_memories icon indicating copy to clipboard operation
project_mern_memories copied to clipboard

TypeError: Cannot read property 'find' of undefined

Open ghostship04 opened this issue 3 years ago • 3 comments

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?

ghostship04 avatar Jul 08 '21 21:07 ghostship04

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

VibhuGautam avatar Jul 10 '21 06:07 VibhuGautam

It worked @VibhuGautam . Thank you so much.

ghostship04 avatar Jul 10 '21 06:07 ghostship04

Thank you! this works

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

mAlex28 avatar Apr 21 '22 16:04 mAlex28