import { useRef, useCallback, useEffect } from 'react';

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

export { useFieldSubmit as default };
//# sourceMappingURL=useFieldSubmit.js.map
