packages/synapse-interface/utils/hooks/useCloseOnEscape.ts
import { useEffect } from 'react'
export const useCloseOnEscape = (onClose) => {
useEffect(() => {
const handleEscapeKey = (event) => {
if (event.key === 'Escape') {
onClose()
}
}
document.addEventListener('keydown', handleEscapeKey)
return () => {
document.removeEventListener('keydown', handleEscapeKey)
}
}, [onClose])
}