mirror of
https://github.com/umami-software/umami.git
synced 2026-02-05 13:17:19 +01:00
Typescript conversion.
This commit is contained in:
parent
366ef35d3d
commit
8775d696b8
29 changed files with 74 additions and 57 deletions
21
src/components/hooks/useEscapeKey.ts
Normal file
21
src/components/hooks/useEscapeKey.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { useEffect, useCallback, KeyboardEvent } from 'react';
|
||||
|
||||
export function useEscapeKey(handler: (event: KeyboardEvent) => void) {
|
||||
const escFunction = useCallback((event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') {
|
||||
handler(event);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener('keydown', escFunction as any, false);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', escFunction as any, false);
|
||||
};
|
||||
}, [escFunction]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default useEscapeKey;
|
||||
Loading…
Add table
Add a link
Reference in a new issue