{"id":18285963,"url":"https://github.com/exodusmovement/use-hot-key","last_synced_at":"2025-04-09T06:21:11.300Z","repository":{"id":66093637,"uuid":"317995880","full_name":"ExodusMovement/use-hot-key","owner":"ExodusMovement","description":"React hook to trigger a callback on keyboard events.","archived":false,"fork":false,"pushed_at":"2020-12-03T02:28:21.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":25,"default_branch":"main","last_synced_at":"2025-02-15T00:42:09.693Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ExodusMovement.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-02T21:26:32.000Z","updated_at":"2020-12-03T02:28:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"9ebdaadf-6b40-4484-9446-ef1907c68568","html_url":"https://github.com/ExodusMovement/use-hot-key","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fuse-hot-key","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fuse-hot-key/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fuse-hot-key/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExodusMovement%2Fuse-hot-key/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ExodusMovement","download_url":"https://codeload.github.com/ExodusMovement/use-hot-key/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247988082,"owners_count":21029047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T13:18:25.105Z","updated_at":"2025-04-09T06:21:11.280Z","avatar_url":"https://github.com/ExodusMovement.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `use-hot-key`\n\n`useHotKey` is a React hook which binds a hotkey combo to a callback for as long as the rendering component remains mounted. The hook automatically clears \u0026 rebinds the callback if the modifiers, key, or callback changes.\n\n## Examples\n\nTo avoid constant rebinding, make sure to use [`useCallback`](https://reactjs.org/docs/hooks-reference.html#usecallback) to create your callbacks.\n\nBasic usage:\n```js\nconst sayHello = useCallback(() =\u003e console.log('hi!'), [])\nuseHotKey('shift+ctrl', 'h', sayHello)\n```\n\nCaps and spaces in the modifiers and key strings don't matter:\n```js\nconst sayHello = useCallback(() =\u003e console.log('hi!'), [])\nuseHotKey('shift + ALT', 'P', sayHello)\n```\n\nCan be used without modifier keys\n```js\nconst unfocus = useCallback(() =\u003e inputRef.current.blur(), [inputRef])\nuseHotKey('', 'Escape', unfocus)\n```\n\nMore than one callback can be bound for the same hotkey at once:\n```js\nconst focusInput = useCallback(() =\u003e searchRef.current.focus(), [searchRef])\nconst blurOtherInput = useCallback(() =\u003e otherRef.current.blur(), [otherRef])\nuseHotKey('ctrl', 'f', focusInput)\nuseHotKey('ctrl', 'f', blurOtherInput)\n```\n\n## Warning\n\nCare should be taken to avoid mounting multiple components (or multiple instances of the same component) at once which attempt to bind the same hotkey to different callbacks. If this happens, all callbacks will fire.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexodusmovement%2Fuse-hot-key","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexodusmovement%2Fuse-hot-key","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexodusmovement%2Fuse-hot-key/lists"}