Socket
Socket
Sign inDemoInstall

@daniel.husar/use-escape-key

Package Overview
Dependencies
6
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @daniel.husar/use-escape-key

React hook for escape key press


Version published
Maintainers
1
Install size
3.18 kB
Created

Readme

Source

use-escape-key

⚠️ Warning: hooks are not part of a stable React release yet, so use this library only for experiments

Demo

About

@danielhusar/use-escape-key is a react custom-hook that will execute function when escape key is pressed

Install

yarn add @daniel.husar/use-escape-key

API

useEscapeKey

This is a hook that lets you execute function when escape key is pressed.

Usage

import useEscapeKey from '@daniel.husar/use-escape-key';
const Component = (props) => {
  useEscapeKey(() => console.log('I have pressed escape key!'));
}

First argument in useEscapeKey is function that will be executed when escape key is pressed. The event object is passed into this function as argument.

Second optional argument is object for options:

window

Type: object Default: 'window object'

This is useful if you don't want to bind event to current window, but for example to parent window (window.parent)

dependencies

Type: array Default: []

If you use in your function any values from the outer scope that change over time, you should provide them as dependencies so function will get executed with latest values. This get passed as second argument into useEffect hook.

License

MIT © Daniel Husar

Keywords

FAQs

Last updated on 29 Oct 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc