"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useCachedTruthy = useCachedTruthy;
var _element = require("@wordpress/element");
/**
 * WordPress dependencies
 */

/**
 * Keeps an up-to-date copy of the passed value and returns it. If value becomes falsy, it will return the last truthy copy.
 *
 * @param {any} value
 * @return {any} value
 */
function useCachedTruthy(value) {
  const [cachedValue, setCachedValue] = (0, _element.useState)(value);
  (0, _element.useEffect)(() => {
    if (value) {
      setCachedValue(value);
    }
  }, [value]);
  return cachedValue;
}
//# sourceMappingURL=use-cached-truthy.js.map