import { useEffect } from 'react' ; export type NamedKey = 'Escape' ; export type KeyboardEventHandler = ( e : KeyboardEvent ) => void ; const useKeyPress = ( key , onKeyPress ) => { useEffect ( ( ) => { const keyPressListener = ( e ) => { if ( e . key === key ) { onKeyPress ( e ) ; } } ; window . addEventListener ( 'keyup' , keyPressListener ) ; return ( ) => window . removeEventListener ( 'keyup' , keyPressListener ) ; } , [ key , onKeyPress ] ) ; } ; export default useKeyPress ;