"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useEventCallback;

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _react = require("react");

function useEventCallback(fn, dependencies) {
  var ref = (0, _react.useRef)(function () {
    throw new Error('Cannot call an event handler while rendering.');
  });
  (0, _react.useEffect)(function () {
    ref.current = fn;
  }, [fn].concat((0, _toConsumableArray2.default)(dependencies)));
  return (0, _react.useCallback)(function () {
    var _fn = ref.current;
    return _fn();
  }, [ref]);
}