
Security News
Official Go SDK for MCP in Development, Stable Release Expected in August
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
react-keyshortcut
Advanced tools
Keyboard Shortcuts Library, wrapper around keypress
npm install react-keyshortcut
or yarn add react-keyshortcut
.import KeyboardShortcut from 'react-keyshortcut'
.<KeyboardShortcut />
. Use combo
, callback
prop for register callback on combo key combination.KeyboardShortcutProvider
and use withShortcut
HOC to get all shortcuts as prop shortcuts
A minimal demo page can be found in example
directory.
Your project needs to use React 16.3 or later.
Add react-keyshortcut to your project by executing npm install react-keyshortcut
or yarn add react-keyshortcut
.
Here's an example of basic usage:
import React, { useState } from 'react';
import KeyboardShortcut from 'react-keyshortcut';
function MyApp() {
const [count, setCount] = useState(0);
return (
<div>
<p>{count}</p>
<KeyboardShortcut
combo={"shift s"}
callback={()=>setCount(count=>count+1)}
value={value}
/>
</div>
);
}
Here's an example of using Multiple KeyboardShortcut:
import React, { useState } from 'react';
import KeyboardShortcut from 'react-keyshortcut';
function MyApp() {
const [count, setCount] = useState(0);
return (
<div>
<p>{count}</p>
<KeyboardShortcut
combo={"shift +"}
callback={()=>setCount(count=>count+1)}
value={value}
/>
<KeyboardShortcut
combo={"shift -"}
callback={()=>setCount(count=>count-1)}
value={value}
/>
</div>
);
}
Here's an example of using KeyboardShortcutProvider and withShortcut:
// App.js
import {KeyboardShortcutProvider} from 'react-keyshortcut';
import ComponentA from './pathof/ComponentA';
import ActiveShortcuts from './pathof/ActiveShortcuts';
function App() {
const [count, setCount] = useState(0);
return (
<KeyboardShortcutProvider>
<ComponentA />
<ActiveShortcuts/>
</KeyboardShortcutProvider>
);
}
export default MyApp
// ComponentA.js
import React, { useState } from 'react';
import KeyboardShortcut from 'react-keyshortcut';
function ComponentA() {
const [count, setCount] = useState(0);
return (
<div>
<p>{count}</p>
<KeyboardShortcut
combo={"shift +"}
callback={()=>setCount(count=>count+1)}
value={value}
/>
<KeyboardShortcut
combo={"shift -"}
callback={()=>setCount(count=>count-1)}
value={value}
/>
</div>
);
}
export default ComponentA
// ActiveShortcuts.js
import React, { useState } from 'react';
import {withShortcut} from 'react-keyshortcut';
function ActiveShortcuts({shortcuts=[]}) {
return (
<div>
<p>shortcuts</p>
{shortcuts && shortcuts.map((shortcut,index)=><p key={index}>{shortcut.combo}:{shortcut.description}</p>)}
</div>
);
}
export default withShortcut(ActiveShortcuts);
Check the example directory in this repository for a full working example.
Prop name | Description | Default value | Example values |
---|---|---|---|
combo | space separated string or an array of strings of key names that describe your combo | "shift a" | |
callback | callback function executed when combo key is pressed | ()=>{} | ()=>setCount(count=>count+1) |
description | string to describe the use of combo | '' | shift a: reset background color |
The MIT License.
![]() |
Shubham Jha whoamishubham@gmail.com https://whoamishubham.github.io |
FAQs
Unknown package
The npm package react-keyshortcut receives a total of 0 weekly downloads. As such, react-keyshortcut popularity was classified as not popular.
We found that react-keyshortcut demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.