UNPKG

@datalayer/core

Version:

[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.io)

19 lines (18 loc) 596 B
/* * Copyright (c) 2023-2025 Datalayer, Inc. * Distributed under the terms of the Modified BSD License. */ import { useCallback, useEffect } from 'react'; export function useKeyboardEscape(handler) { const handleKeyboardEscape = useCallback(event => { if (event.key === 'Escape') { handler(); } }, [handler]); useEffect(() => { document.addEventListener('keydown', handleKeyboardEscape, false); return () => { document.removeEventListener('keydown', handleKeyboardEscape, false); }; }, [handleKeyboardEscape]); }