Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
import { useEffect } from 'react';
export default function useEscapeToClose(onClose: () => void) {
useEffect(() => {
function handleKeyDown(e: KeyboardEvent) {
if (e.keyCode === 27) {
onClose();
}
}
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, [onClose]);
}