@sanity/preview-kit
Version:
General purpose utils for live content and visual editing
47 lines (46 loc) • 1.36 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { lazy, Children, isValidElement } from "react";
const ClientComponent = lazy(() => import("@sanity/preview-kit/live-query/client-component")), DEFAULT_PARAMS = {};
function LiveQuery(props) {
if (!props.enabled)
return props.children;
const { query, params = DEFAULT_PARAMS, initialData, as: LiveComponent } = props;
if (LiveComponent) {
if (Children.count(props.children) > 1)
throw new Error("LiveQuery: `as` prop can only be used with a single child");
if (!isValidElement(props.children))
throw new Error("LiveQuery: `as` prop requires a valid `children` prop");
return /* @__PURE__ */ jsx(
ClientComponent,
{
initialData,
query,
params,
throwOnMissingProvider: props.throwOnMissingProvider,
children: /* @__PURE__ */ jsx(
LiveComponent,
{
// eslint-disable-next-line no-warning-comments
// @ts-expect-error -- @todo fix the typings
...props.children.props
}
)
}
);
}
return /* @__PURE__ */ jsx(
ClientComponent,
{
initialData,
query,
params,
children: props.children
}
);
}
LiveQuery.displayName = "LiveQuery";
export {
LiveQuery,
LiveQuery as default
};
//# sourceMappingURL=live-query.js.map