Proper use of useEffect with KeyboardEvent eventListener
If there is state in my onKeyDown function which is set in document.addEventListener("keydown", onKeyDown), how would i keep my state within onKeyDown from getting stale?
Should it be added as a dependency in my useEffect? For example:
4 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
does it matter if i define it outside or inside the useeffect? i guess it gets redfined on re-render but thats not expensive right?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Sweet thanks