Listen to key down events with React hooks.
npm install use-key-down
oryarn add use-key-down
import useKeyDown from 'use-key-down';
function App() {
const isEnterKeyDown = useKeyDown('Enter');
return <p>The Enter key is {isEnterKeyDown ? 'down' : 'up'}.</p>;
}
useKeyDown
only takes one parameter, a string representing the key to which
you want to listen to key down events.
If you are a fan of this project, you may become a sponsor via GitHub's Sponsors Program.