"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = useEscapeEffect;

var _require = require('react'),
    useEffect = _require.useEffect;

var ESCAPE_CODE = "Escape";
var _dependencies = [];

function useEscapeEffect(callback) {
  var dependencies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  useEffect(function () {
    if (!callback) {
      return;
    }

    if (!Array.isArray(dependencies)) {
      dependencies = _dependencies;
      console.log('Dependencies must be an array!');
    }

    function onKeyDown(event) {
      if (event.code === ESCAPE_CODE) {
        callback(event);
      }
    }

    document.addEventListener('keydown', onKeyDown);
    return function () {
      document.removeEventListener('keydown', onKeyDown);
    };
  }, dependencies);
}

;