import { useEffect } from 'react' ; const useKeyDown = ( targetKey , func , delay = 0 , modifierKeys = [ ] ) : void => { useEffect ( ( ) => { const handleKeyDown = ( event ) => { if ( targetKey == null || event . key === targetKey ) { if ( modifierKeys . every ( ( key ) => event [ `${ key }Key` ] ) ) { func ( event ) ; } } } ; const timer = setTimeout ( ( ) => { window . addEventListener ( 'keydown' , handleKeyDown ) ; } , delay ) ; return ( ) => { clearTimeout ( timer ) ; window . removeEventListener ( 'keydown' , handleKeyDown ) ; } ; } , [ ] ) ; } ; export default useKeyDown ;