项目作者: smarthug

项目描述 :
A react hooks wrapper of @github/hotkey
高级语言: JavaScript
项目地址: git://github.com/smarthug/useHotkey.git
创建时间: 2021-08-05T07:35:53Z
项目社区:https://github.com/smarthug/useHotkey

开源协议:MIT License

下载


use-github-hotkey

react hooks of @github/hotkey

NPM JavaScript Style Guide

Feature

  • A react hooks wrapper of @github/hotkey
  • The easiest API possible
  • Coded perfectly for react component lifecycle
  • Supports triggering Function with hotkey. HTML DOM is not necessary.

Demo

https://smarthug.github.io/useHotkey/

Install

  1. npm install use-github-hotkey

Usage

  1. import React from 'react'
  2. import { useHotkey, installFuncHotkey } from 'use-github-hotkey'
  3. export default function App() {
  4. // keyboard shortcut with dom
  5. const setTestShortcut = useHotkey("t e")
  6. // keyboard shortcut with function
  7. installFuncHotkey(handleFunction, "t t")
  8. function handleClick() {
  9. alert("t e clicked");
  10. }
  11. function handleFunction() {
  12. alert("t t clicked");
  13. }
  14. return (
  15. <div>
  16. <h1>example</h1>
  17. <button ref={setTestShortcut} onClick={handleClick} >press "t e" to click this button with hotkey</button>
  18. <h3>press "t t" to invoke function with hotkey</h3>
  19. </div>
  20. )
  21. }

License

MIT © smarthug