Skip to main content
Version: 5.7.3

useKeyBindings

About#

useKeyBindings can bind pairs of keyboard events and handlers.

Installation#

npm install rooks

Importing the hook#

import { useKeyBindings } from "rooks";

Usage#

function Demo() {
const cb1 = () => console.log("cb1");
const cb2 = () => console.log("cb2");
const cb3 = () => console.log("cb3");
useKeyBindings({ 1: cb1, 2: cb2, Enter: cb3 });
return (
<div>
<input type="text" />
</div>
);
}
render(<Demo />);

Arguments#

ArgumentTypeDescriptionDefault value
keyBindingsObjectpairs of keyboard events and handlers{}
optionsOptionsrefer to useKey{}

Codesandbox Examples#

Basic Usage#


Join Bhargav's discord server#

You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.

Last updated on by imbhargav5