jonasschmedtmann / ultimate-react-course

Starter files, final projects, and FAQ for my Ultimate React course
3.25k stars 1.99k forks source link

[07-usepopcorn]Issue with event listener cleanup in useEffect #58

Open FoundDream opened 7 months ago

FoundDream commented 7 months ago

file: app-v3.js line-179,180

The code snippet provided seems to have a problem with the cleanup of the event listener in the useEffect hook. In the cleanup function, the event listener is added again instead of being removed using removeEventListener. This can lead to unexpected behavior and potential memory leaks.

Proposed Solution: Modify the cleanup function in the useEffect hook to properly remove the event listener using removeEventListener. Also, include inputEl.current in the dependency array to handle changes to inputEl.current correctly. issue

lawuysal commented 6 months ago

Yes, you got it right. He did it right in the video but he might accidentally changed it. I checked now and he changed the anonymous function to an arrow function.