UNPKG

@suspensive/react

Version:

Suspensive interfaces for react

39 lines (36 loc) 1.69 kB
'use client'; import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.130.0/helpers/objectSpread2.mjs"; import { SuspenseDefaultPropsContext } from "./contexts/DefaultPropsContexts.mjs"; import { defineSuspense } from "./utils/defineSuspense.mjs"; import { _objectWithoutProperties } from "./_virtual/_@oxc-project_runtime@0.130.0/helpers/objectWithoutProperties.mjs"; import { useContext } from "react"; import { jsx } from "react/jsx-runtime"; //#region src/Suspense.tsx const _excluded = [ "clientOnly", "fallback", "children", "name" ]; /** * This component is just wrapping React's Suspense. to use Suspense easily in Server-side rendering environment like Next.js * @see {@link https://suspensive.org/docs/react/Suspense Suspensive Docs} */ const Suspense = Object.assign((_ref) => { let { clientOnly, fallback, children, name } = _ref, rest = _objectWithoutProperties(_ref, _excluded); const defaultProps = useContext(SuspenseDefaultPropsContext); return /* @__PURE__ */ jsx(defineSuspense({ defaultPropsClientOnly: defaultProps.clientOnly, componentPropsClientOnly: clientOnly }), _objectSpread2(_objectSpread2({}, rest), {}, { fallback: fallback === void 0 ? defaultProps.fallback : fallback, name, children })); }, { displayName: "Suspense", with: (suspenseProps, Component) => Object.assign((props) => /* @__PURE__ */ jsx(Suspense, _objectSpread2(_objectSpread2({}, suspenseProps), {}, { children: /* @__PURE__ */ jsx(Component, _objectSpread2({}, props)) })), { displayName: `${Suspense.displayName}.with(${Component.displayName || Component.name || "Component"})` }) }); //#endregion export { Suspense }; //# sourceMappingURL=Suspense.mjs.map