DEV Community

Discussion on: Why pressing the key works only once in my React project?

Collapse
 
merri profile image
Vesa Piittinen

The second one causes slightly less work for CPU to do, although the effect is quite minimal with today's computing power. And the work only happens when the value changes, in this case from user action, so not really a big argument for it.

However it is always a good idea to clean up what you create to the DOM, so in this case by adding the removeEventListener part even if using the second approach.

Thread Thread
 
ptifur profile image
Yar

Thank you! Makes sense.