DEV Community

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

erandakarachchi profile image
Eranda Kudalugodaarachchi • Edited on

When we add itWorks as a dependency to useEffect, It will re-render for each change of itWorks value. So here it will cause the number of event listeners to multiply at each change.
So as @Vesa Piittinen suggests it is a good idea to remove the listener if you are adding it in the useEffect hook.