8000 GitHub - salilgupta2510/react-short-keys: Keyboard shortcut component for React
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

salilgupta2510/react-short-keys

 
 

Repository files navigation

react-short-keys

npm package

A React component to capture and action on keyboard key press.

Install

Install via npm or yarn

npm i react-short-keys -S

or

yarn add react-short-keys

#Use

Add the KeyPress component where you need to handle a keypress e.g

class Demo extends Component {

  state = {key: ''};

  setKey = event => this.setState({key: event.key});

  render() {
    const {
      key
    } = this.state;

    return (
        <div>
          <h1>react-short-keys Demo Yo!</h1>
          <KeyPress
               38, 39, 40]}
              
          />
          <HandleKeyTriggers
              pressedKey={key}
          />
        </div>
      )
  }
}

The above example listens for the arrow keys and triggers a function only when an arrow key is triggered.

alt text

#edited

Edit commonCodes.js in /src/objects which would work with the default KeyPress component.

About

Keyboard shortcut component for React

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%
0