All files / atom/pinInput/src/hooks useKeyPress.js

100% Statements 10/10
50% Branches 2/4
100% Functions 4/4
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19    1x 5x 5x 5x 5x 5x   5x 5x 5x              
import {useEffect} from 'react'
 
const useKeyPress = (callback, {target, onChange}) => {
  const events = []
  return useEffect(() => {
    const element = target?.current
    Eif (element) {
      events.push(element.addEventListener('keydown', callback))
    }
    return () => {
      events.forEach(event => {
        Eif (element) element.removeEventListener('keydown', callback)
      })
    }
  }, [target, callback, onChange]) // eslint-disable-line react-hooks/exhaustive-deps
}
 
export default useKeyPress