Liferay.Loader.define("layout-content-page-editor-web@2.0.170/page_editor/core/hooks/useLazy", ['module', 'exports', 'require', 'frontend-js-react-web$react'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = useLazy;

    var _react = _interopRequireDefault(require("frontend-js-react-web$react"));

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    /**
     * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
     * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
     */
    var lazy = _react.default.lazy,
        useCallback = _react.default.useCallback,
        useRef = _react.default.useRef;
    /**
     * Returns a component that takes a `pluginId` and a `getInstance`
     * function (for obtaining a promise of a plugin instance) and wraps it
     * in a `React.lazy` wrapper.
     *
     * The supplied callback will be called with the plugin instance once the
     * promise resolves, and should return something to be rendered.
     */

    function useLazy(callback) {
      var components = useRef(new Map());
      return useCallback(function (_ref) {
        var getInstance = _ref.getInstance,
            pluginId = _ref.pluginId;

        if (!components.current.has(pluginId)) {
          var plugin = getInstance(pluginId);

          var _Component = lazy(function () {
            return plugin.then(function (instance) {
              return {
                default: function _default() {
                  if (instance) {
                    return callback({
                      instance: instance
                    });
                  } else {
                    return null;
                  }
                }
              };
            });
          });

          components.current.set(pluginId, _Component);
        }

        var Component = components.current.get(pluginId);
        return (/*#__PURE__*/_react.default.createElement(Component, null)
        );
      }, [callback]);
    }
    //# sourceMappingURL=useLazy.js.map
  }
});
//# sourceMappingURL=useLazy.js.map