DEV Community

Discussion on: React *Cannot read property 'addEventListener' of undefined*

Collapse
 
khauri profile image
Khauri • Edited

When you import a module the code inside it runs immediately. In this case your Count.js file is being run before React has a chance to mount your app and put the textarea into the document. So when you call querySelectorAll, the textarea is not found and input is therefore undefined.

You might consider instead converting that peace to react as well or using a useEffect hook to make sure the code is run only when it's ready to.