UNPKG

@whop/react

Version:

React SDK for building embedded apps on Whop

51 lines (50 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get }); } _export(exports, { get EMBEDDED_CHECKOUT_IFRAME_SANDBOX_STRING () { return EMBEDDED_CHECKOUT_IFRAME_SANDBOX_STRING; }, get useEmbeddedCheckoutIframeUrl () { return useEmbeddedCheckoutIframeUrl; } }); const _util = require("@whop/checkout/util"); const _react = require("react"); const _uselazyref = require("../util/use-lazy-ref"); function useEmbeddedCheckoutIframeUrl(...params) { const { current: iframeUrl } = (0, _uselazyref.useLazyRef)(()=>(0, _util.getEmbeddedCheckoutIframeUrl)(...params)); useWarnOnIframeUrlChange(iframeUrl, ...params); return iframeUrl; } function useWarnOnIframeUrlChange(iframeUrl, ...[planId, theme, sessionId, _origin, hidePrice, skipRedirect, utm, styles, prefill, themeOptions, hideSubmitButton, hideTermsAndConditions]) { const updatedIframeUrl = (0, _react.useMemo)(()=>(0, _util.getEmbeddedCheckoutIframeUrl)(planId, theme, sessionId, undefined, hidePrice, skipRedirect, utm, styles, prefill, themeOptions, hideSubmitButton, hideTermsAndConditions), [ planId, theme, sessionId, hidePrice, skipRedirect, utm, styles, prefill, themeOptions, hideSubmitButton, hideTermsAndConditions ]); (0, _react.useEffect)(()=>{ if (iframeUrl !== updatedIframeUrl && process.env.NODE_ENV === "development") { console.warn(`[WhopCheckoutEmbed] iframeUrl changed from ${iframeUrl} to ${updatedIframeUrl}. Updating props on the checkout embed is not supported. Please rerender the component.`); } }, [ iframeUrl, updatedIframeUrl ]); } const EMBEDDED_CHECKOUT_IFRAME_SANDBOX_STRING = _util.EMBEDDED_CHECKOUT_IFRAME_SANDBOX_LIST.join(" ");