Skip to content

Commit

Permalink
fix: Adding a cleanup function to add a removeEventListener to preven…
Browse files Browse the repository at this point in the history
…t hangs while pressing ESC
  • Loading branch information
Ali Unwala committed Sep 10, 2020
1 parent e9d2f53 commit fbc9f0c
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,19 @@ const GlobalSearchInput = () => {
);

useEffect(() => {
document.addEventListener('keyup', function(e){
var collapseOpenNavs = function(e){
if(e.which == 27){
toggleNavState('switcherIsOpen', 'close');
toggleNavState('searchIsOpen', 'close');
}
})
};

document.addEventListener('keyup',collapseOpenNavs)

return function cleanup(){
document.removeEventListener('keyup', collapseOpenNavs)
};

})

useEffect(() => {
Expand Down

0 comments on commit fbc9f0c

Please sign in to comment.