@whop/react
Version:
React SDK for building embedded apps on Whop
33 lines (32 loc) • 1.54 kB
JavaScript
import { EMBEDDED_CHECKOUT_IFRAME_SANDBOX_LIST, getEmbeddedCheckoutIframeUrl } from "@whop/checkout/util";
import { useEffect, useMemo } from "react";
import { useLazyRef } from "../util/use-lazy-ref.mjs";
export function useEmbeddedCheckoutIframeUrl(...params) {
const { current: iframeUrl } = useLazyRef(()=>getEmbeddedCheckoutIframeUrl(...params));
useWarnOnIframeUrlChange(iframeUrl, ...params);
return iframeUrl;
}
function useWarnOnIframeUrlChange(iframeUrl, ...[planId, theme, sessionId, _origin, hidePrice, skipRedirect, utm, styles, prefill, themeOptions, hideSubmitButton, hideTermsAndConditions]) {
const updatedIframeUrl = useMemo(()=>getEmbeddedCheckoutIframeUrl(planId, theme, sessionId, undefined, hidePrice, skipRedirect, utm, styles, prefill, themeOptions, hideSubmitButton, hideTermsAndConditions), [
planId,
theme,
sessionId,
hidePrice,
skipRedirect,
utm,
styles,
prefill,
themeOptions,
hideSubmitButton,
hideTermsAndConditions
]);
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
]);
}
export const EMBEDDED_CHECKOUT_IFRAME_SANDBOX_STRING = EMBEDDED_CHECKOUT_IFRAME_SANDBOX_LIST.join(" ");