Spaces:
Configuration error
Configuration error
Download src/components/hooks/useEscapeKey.ts from SreejithSHR/umami: direct link, hf CLI and curl.
- Browser
- Download file 530 Bytes
-
https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/hooks/useEscapeKey.ts
- Command line
-
hf download hf://spaces/SreejithSHR/umami/src/components/hooks/useEscapeKey.ts
-
curl -L -o useEscapeKey.ts https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/hooks/useEscapeKey.ts
530 Bytes
| 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; | |