UNPKG

hydrogen-sanity

Version:
43 lines (40 loc) 1.18 kB
import { jsx, Fragment } from 'react/jsx-runtime'; function assertSanityProviderValue(value) { if (typeof value === "undefined") { throw new Error( "Failed to find a Sanity provider value. Did you forget to wrap your app in a `SanityProvider`?" ); } return true; } function useSanityProviderValue() { const providerValue = globalThis[/* @__PURE__ */ Symbol.for("Sanity Provider")]; assertSanityProviderValue(providerValue); return providerValue; } function SanityProvider({ value, children }) { setProviderValue(value); return /* @__PURE__ */ jsx(Fragment, { children }); } function Sanity(props) { const providerValue = useSanityProviderValue(); assertSanityProviderValue(providerValue); return /* @__PURE__ */ jsx( "script", { ...props, dangerouslySetInnerHTML: { __html: `(${setProviderValue})(${JSON.stringify(providerValue)})` }, suppressHydrationWarning: true } ); } function setProviderValue(value) { globalThis[/* @__PURE__ */ Symbol.for("Sanity Provider")] = Object.freeze(value); } export { Sanity, SanityProvider, useSanityProviderValue }; //# sourceMappingURL=provider.js.map