
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
react-shortcut-hoc
Advanced tools
Enhance a React component with a Higher Order Component that provides global keyboard event combination detection. Example: Ctrl+Enter or Ctrl+Shift+Enter
The package can be installed via NPM repository:
npm install react-click-outside
Import package with ES6 importing function, and decorate your component with it.
import shortcutDecorator from 'react-shortcut-hoc
shortcutDecorator(wrapped-component, shortcut-pattern, callback-function-name)
import shortcut from 'react-shortcut-hoc'
class WrappedComponent extends React.Component {
/**
* This method will be called everytime users hit the combination (ctrl+enter or ctrl+shift+enter)
*/
onCallback(event) {
console.log(event)
}
render() {
return <div>This is a test component</div>
}
}
export default shortcut(WrappedComponent, 'ctrl+enter ctrl+shift+enter', 'onCallback');
You can combine three functional keys: ctrl, alt and shift with below list of character to make a shortcut pattern. Then join all shortcut patterns in a string and seperated them by whitespace
0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z ` - = [ ] \ ; ' , . /
"ctrl+shift+k+i ctrl+alt+o"
Released under the MIT license.
FAQs
Add document keyboard shortcuts to react-component
We found that react-shortcut-hoc 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.