Close the profile password modal via 'Esc' key

This commit is contained in:
Adam Coard committed 2020-09-29 23:32:17 +00:00
1 parent d67d75a8e7
commit 6f929378f0
2 files changed
+24

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
import { useEffect, useCallback } from 'react';
export default function useEscapeKey(handler) {
const escFunction = useCallback(event => {
if (event.keyCode === 27) {
handler(event);
}
}, []);
useEffect(() => {
document.addEventListener('keydown', escFunction, false);
return () => {
document.removeEventListener('keydown', escFunction, false);
};
}, [escFunction]);
return null;
}