mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-23 18:41:36 +01:00
22 lines
450 B
JavaScript
22 lines
450 B
JavaScript
import { useEffect, useCallback } from 'react';
|
|
|
|
export 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;
|
|
}
|
|
|
|
export default useEscapeKey;
|