'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
