"use strict";

exports.__esModule = true;
exports.default = useKeyboard;

var _react = require("react");

function useKeyboard(targetKey, callback) {
  // If pressed key is our target key then set to true
  function downHandler(event) {
    const {
      key
    } = event;

    if (key === targetKey) {
      callback && callback(event);
    }
  } // Add event listeners


  (0, _react.useEffect)(() => {
    window.addEventListener("keydown", downHandler); // Remove event listeners on cleanup

    return () => {
      window.removeEventListener("keydown", downHandler);
    };
  }, [downHandler]); // Empty array ensures that effect is only run on mount and unmount

  return;
}

module.exports = exports.default;