Thanks Eranda! Seems like it doubles the number of added key listeners with each press and soon the application stops responding.
Which means the answer is to remove keyListeners and clean up useEffect an some point? Not sure how, I've reached the limit of my Hooks understanding 😜
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks Eranda! Seems like it doubles the number of added key listeners with each press and soon the application stops responding.
Which means the answer is to remove keyListeners and clean up useEffect an some point? Not sure how, I've reached the limit of my Hooks understanding 😜
When we add
itWorks
as a dependency to useEffect, It will re-render for each change ofitWorks
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.