@daniel.husar/use-escape-key

    1.0.4 • Public • Published

    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

    Install

    npm i @daniel.husar/use-escape-key

    DownloadsWeekly Downloads

    1

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    3.25 kB

    Total Files

    3

    Last publish

    Collaborators

    • avatar