Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
FoundDream opened this issue Mar 29, 2024 · 1 comment
Open

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

FoundDream opened this issue Mar 29, 2024 · 1 comment

Comments

@FoundDream
Copy link

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
Copy link

lawuysal commented May 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants