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.
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.
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.