Listening For Key Press

To listen for key press, you can do this:


useEffect(() => {
  function handleKeyPress(e) {
    console.log(e.key);
  }
  window.addEventListener('keypress', handleKeyPress);
  return () => window.removeEventListener('keypress', handleKeyPress);
}, []);