Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.