⚠️ Warning: hooks are not part of a stable React release yet, so use this library only for experiments
@danielhusar/use-escape-key is a react custom-hook that will execute function when escape key is pressed
yarn add @daniel.husar/use-escape-key
This is a hook that lets you execute function when escape key is pressed.
import useEscapeKey from '@daniel.husar/use-escape-key';const Component = props;
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:
This is useful if you don't want to bind event to current window, but for example to parent window (window.parent)
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
MIT © Daniel Husar