This is just a technology testing project based on Create React App and TailwindCSS
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

16 linhas
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. }