Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
import { type KeyboardEvent, useCallback, useEffect } 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;
}