'use strict';

var react = require('react');

var useFieldSubmit = function useFieldSubmit(onSubmit) {
  /** @type {{ current: HTMLInputElement & HTMLTextAreaElement }} */
  // @ts-ignore
  var ref = react.useRef(null);
  var keyDownHandler = react.useCallback(function (event) {
    if (event.key !== "Enter") return;
    if (event.shiftKey) {
      event.stopPropagation();
    } else {
      onSubmit();
      event.preventDefault();
    }
  }, []);
  react.useEffect(function () {
    var element = ref.current;
    if (!element) return undefined;
    element.addEventListener("keydown", keyDownHandler);
    return function () {
      return element.removeEventListener("keydown", keyDownHandler);
    };
  }, []);
  return ref;
};

module.exports = useFieldSubmit;
//# sourceMappingURL=useFieldSubmit.js.map
