'use strict';

var neptuneValidation = require('@transferwise/neptune-validation');
var React = require('react');

const useConditionalListener = ({
  attachListener,
  callback,
  eventType,
  parent
}) => {
  React.useEffect(() => {
    if (attachListener && !neptuneValidation.isUndefined(parent)) {
      parent.addEventListener(eventType, callback, true);
    }
    return () => {
      if (!neptuneValidation.isUndefined(parent)) {
        parent.removeEventListener(eventType, callback, true);
      }
    };
  }, [attachListener, callback, eventType, parent]);
};

exports.useConditionalListener = useConditionalListener;
//# sourceMappingURL=useConditionalListener.js.map
