hoc.js 755 B

12345678910111213141516171819
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.sidecar = void 0;
  4. var tslib_1 = require("tslib");
  5. var React = tslib_1.__importStar(require("react"));
  6. var hook_1 = require("./hook");
  7. // eslint-disable-next-line @typescript-eslint/ban-types
  8. function sidecar(importer, errorComponent) {
  9. var ErrorCase = function () { return errorComponent; };
  10. return function Sidecar(props) {
  11. var _a = (0, hook_1.useSidecar)(importer, props.sideCar), Car = _a[0], error = _a[1];
  12. if (error && errorComponent) {
  13. return ErrorCase;
  14. }
  15. // @ts-expect-error type shenanigans
  16. return Car ? React.createElement(Car, tslib_1.__assign({}, props)) : null;
  17. };
  18. }
  19. exports.sidecar = sidecar;