"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useAutofocus = exports.default = void 0;
var _compat = require("preact/compat");
/**
 * Returns a ref and will focus on the element that ref is attached to
 * if the `autoFocus` boolean parameter is truthy.
 */
const useAutofocus = autoFocus => {
  const ref = (0, _compat.useRef)();
  (0, _compat.useEffect)(() => {
    if (autoFocus && ref.current?.focus) {
      ref.current?.focus();
    }
  }, [ref, autoFocus]);
  return ref;
};
exports.useAutofocus = useAutofocus;
var _default = exports.default = useAutofocus;