import { useEffect } from "react" ; type Code = "ArrowDown" | "ArrowUp" | "Enter" ; export const useKeyDown = ( code , cb ) => { useEffect ( ( ) => { const handleKeyPress = ( event ) => { if ( event . code === code ) { cb ( ) ; } } ; window . addEventListener ( "keydown" , handleKeyPress ) ; return ( ) => { window . removeEventListener ( "keydown" , handleKeyPress ) ; } ; } , [ code , cb ] ) ; } ;