Handle React state inside an event listener callback
Without recreating your function on every render.
Published in
3 min readNov 24, 2021
The other day my girlfriend danwessels was working on a feature where you could navigate a carousel of images using your keyboard arrows. The carousel already had this functionality with UI arrows but humans are lazy and don’t want to move the cursor and click on buttons. A simple enough…