This is just a technology testing project based on Create React App and TailwindCSS
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

16 lines
465B

  1. import { useEffect } from 'react';
  2. /**
  3. * useKeyPress
  4. * @param {string} key - the name of the key to respond to, compared against event.key
  5. * @param {function} action - the action to perform on key press
  6. */
  7. export default function useKeypress(key, action) {
  8. useEffect(() => {
  9. function onKeyup(e) {
  10. if (e.key === key) action()
  11. }
  12. window.addEventListener('keyup', onKeyup);
  13. return () => window.removeEventListener('keyup', onKeyup);
  14. });
  15. }