* remove tiny keys

* fix: replace library with code

* cleanup

* add lodash throttle

add dependency to handle event throttling

* Revert "add lodash throttle"

This reverts commit abcbd3556b.
This commit is contained in:
Carlos Valente
2021-11-17 22:50:54 +01:00
committed by GitHub
parent 17d5c84133
commit f3320efc5c
6 changed files with 79 additions and 56 deletions
+16 -11
View File
@@ -1,8 +1,7 @@
import { Link, Redirect } from 'react-router-dom';
import { Image } from '@chakra-ui/react';
import { AnimatePresence, motion } from 'framer-motion';
import { useState, useEffect } from 'react';
import tinykeys from 'tinykeys';
import { useState, useEffect, useCallback } from 'react';
import navlogo from 'assets/images/logos/LOGO-72.png';
import style from './NavLogo.module.css';
@@ -14,17 +13,23 @@ export default function NavLogo() {
};
// Handle keyboard shortcuts
useEffect(() => {
let unsubscribe = tinykeys(window, {
Space: () => {
setShowNav((s) => !s);
},
});
return () => {
unsubscribe();
};
const handleKeyPress = useCallback((e) => {
// Space bar
if (e.keyCode === 32) {
setShowNav((s) => !s);
}
}, []);
useEffect(() => {
// attach the event listener
document.addEventListener('keydown', handleKeyPress);
// remove the event listener
return () => {
document.removeEventListener('keydown', handleKeyPress);
};
}, [handleKeyPress]);
return (
<motion.div
initial={{ opacity: 0.5 }}