An open API service indexing awesome lists of open source software.

https://github.com/officialpesonen/use-keybinds

A lightweight and typesafe library for managing keybinds in React applications.
https://github.com/officialpesonen/use-keybinds

keybinds react

Last synced: 8 months ago
JSON representation

A lightweight and typesafe library for managing keybinds in React applications.

Awesome Lists containing this project

README

          

# use-keybinds
A lightweight and typesafe library for managing keybinds in React applications.

## Features
- Single keypresses such as (ArrowUP)
- Multiple keypresses such as (Ctrl + C)
- Sequential keypresses such as (G then H)

## Usage
```tsx
import {KeybindsProvider, useKeybinds} from "use-keybinds";

// Optional but heavily recommended for type safety
export type KeybindSlug = "SUBMIT" | "GO_TO_HOME";

const App = () => {
return (

keybinds={{
SUBMIT: {
name: "Submit form",
keybind: ["Enter"]
},
GO_TO_HOME: {
name: "Go to home",
keybind: ["KeyG", "KeyH"],
isSequential: true
}
}}
>


);
};

const Component = () => {
const [current, setCurrent] = useState("");

useKeybinds({
SUBMIT: (e) => {
e.preventDefault();
setCurrent("submit")
},
GO_TO_HOME: (e) => {
e.preventDefault();
setCurrent("go to home")
}
})

return (


Current keybind: {current}



)
}
```

## License
MIT