reshow-return
Version:
reshow-return (simple connect component with reshow-flux)
51 lines (48 loc) • 1.5 kB
JavaScript
import _objectWithoutProperties from "reshow-runtime/es/helpers/objectWithoutProperties";
var _excluded = ["isHydrate"],
_excluded2 = ["children", "backfillProps"];
// @ts-check
import * as React from "react";
import build from "reshow-build";
import { useLoaded } from "reshow-hooks";
import { connectOptions } from "reshow-return";
import hydrate from "../../hydrate.mjs";
/**
* Example:
* https://github.com/react-atomic/reshow/blob/main/packages/reshow-url/src/ui/organisms/UrlReturn.jsx
* @param {React.ReactNode} comp
* @param {string[]} cleanProps
* @returns {React.ElementType}
*/
var ClientReturnHoc = function ClientReturnHoc(comp, cleanProps) {
/**
* @typedef {object} ClientReturnType
* @property {boolean} [isHydrate]
* @property {React.ReactNode} [children]
* @property {boolean} [backfillProps]
* @property {any} [props]
*/
/**
* @param {ClientReturnType} allprops
*/
var ClientReturn = function ClientReturn(_ref) {
var {
isHydrate
} = _ref,
props = _objectWithoutProperties(_ref, _excluded);
if (hydrate() || isHydrate) {
var isLoad = useLoaded();
if (!isLoad) {
var {
children,
backfillProps
} = props,
restProps = _objectWithoutProperties(props, _excluded2);
return build(children)(connectOptions.reset(restProps, cleanProps));
}
}
return build(comp)(props);
};
return ClientReturn;
};
export default ClientReturnHoc;