window.postMessage
.
Since this package relies on window.postMessage
, it only works in Client Components.
Setup
The main function exported from this package is thecreateAppIframeSDK
function. When called, this function sets up a listener for messages from the main Whop site, using window.on('message', ...)
.
Next.js Setup
If you’re using Next.js, you’ll need to make sure that you’re only callingcreateAppIframeSDK
on the client. You can do this by using a client
layout defined in the root of your app.
Here is an example of the project structure:
app/layout.tsx
app/layout.client.tsx
lib/iframe.ts
We have now setup the SDK and iFrame.