Skip to content

Instantly share code, notes, and snippets.

@karenying
Created June 16, 2020 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karenying/67192e644c76dcb4621a37e737f005b2 to your computer and use it in GitHub Desktop.
Save karenying/67192e644c76dcb4621a37e737f005b2 to your computer and use it in GitHub Desktop.
useEffect(() => {
const handleKeyDown = (e) => {
if (e.keyCode === 39) {
onArrowClick('right');
}
if (e.keyCode === 37) {
onArrowClick('left');
}
};
window.addEventListener('keydown', handleKeyDown);
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment