# SuperwallLoading Source: https://superwall.com/docs/expo/sdk-reference/components/SuperwallLoading undefined `` is a component that renders its children only when Superwall is loading or not yet configured. This component can be used to display a loading indicator or a placeholder while the Superwall SDK is initializing. Once Superwall is configured and no longer in a loading state, this component will render `null`. **Note:** This component will not render if there's a configuration error. Use `` to handle error states. ## Props | Name | Type | Description | Required | | -------- | --------------- | ------------------------------------------------------------------- | -------- | | children | React.ReactNode | Content to render while Superwall is loading or not yet configured. | yes | ## Example ```tsx import { SuperwallProvider, SuperwallLoading, SuperwallLoaded, SuperwallError, } from "expo-superwall"; import { ActivityIndicator, View, Text } from "react-native"; const API_KEY = "YOUR_SUPERWALL_API_KEY"; export default function App() { return ( Failed to load Superwall {/* Your main app screen or component */} ); } function MainAppScreen() { return ( Superwall SDK is ready! {/* Rest of your app's UI */} ); } ``` ## Related Components * [``](/expo/sdk-reference/components/SuperwallLoaded) - Renders children when Superwall is ready * [``](/expo/sdk-reference/components/SuperwallError) - Renders children when Superwall configuration fails --- # SuperwallLoaded Source: https://superwall.com/docs/expo/sdk-reference/components/SuperwallLoaded undefined `` is a component that renders its children only when Superwall has finished loading and is configured. This component is useful for conditionally rendering parts of your UI that depend on Superwall being ready. If Superwall is still loading, has not been configured, or has a configuration error, this component will render `null`. ## Props | Name | Type | Description | Required | | -------- | --------------- | ---------------------------------------------------------- | -------- | | children | React.ReactNode | Content to render once Superwall is loaded and configured. | yes | ## Example ```tsx import { SuperwallProvider, SuperwallLoading, SuperwallLoaded, SuperwallError, } from "expo-superwall"; import { ActivityIndicator, View, Text } from "react-native"; const API_KEY = "YOUR_SUPERWALL_API_KEY"; export default function App() { return ( Failed to load Superwall {/* Your main app screen or component */} ); } function MainAppScreen() { return ( Superwall SDK is ready! {/* Rest of your app's UI */} ); } ``` ## Notes * This component will not render if there's a configuration error. Use `` to handle error states. * This component will not render while Superwall is loading. Use `` to show loading states. * Use this component alongside `` and `` to provide a complete loading/error/success UI flow. --- # CustomPurchaseControllerProvider Source: https://superwall.com/docs/expo/sdk-reference/components/CustomPurchaseControllerProvider A modern, hooks-based approach to handling purchases and purchase restores with the Superwall SDK. The `CustomPurchaseControllerProvider` component allows you to integrate your own purchase handling logic with the Superwall SDK. It provides a modern, hooks-based approach to handling purchases and purchase restores. ## Usage ```tsx import { CustomPurchaseControllerProvider } from 'expo-superwall' import { SuperwallProvider } from 'expo-superwall' export default function App() { return ( { if (params.platform === "ios") { console.log("iOS purchase:", params) // Handle iOS purchase with StoreKit } else { console.log("Android purchase:", params.productId) // Handle Android purchase with Google Play Billing } }, onPurchaseRestore: async () => { console.log("Restore purchases requested") // Handle restore purchases logic }, }} > {/* Your app content */} ) } ``` **Important:** The `onPurchase` and `onPurchaseRestore` callbacks communicate the outcome through the resolved value or an error: * **Return/resolve `void` or a success result** → Superwall records a successful purchase or restore * **Return a failure/cancelled result or throw** → Superwall records a failed or cancelled outcome If your purchase function returns a status like `"cancelled"` or `"error"`, return a `PurchaseResult` with that type (or throw) so Superwall records the correct outcome: ```tsx onPurchase: async (params) => { const result = await yourPurchaseFunction(params.productId); if (result !== "success") { return { type: "failed", error: `Purchase ${result}` }; } // Only reaches here on success }, ``` **Why this matters:** If your callback resolves without signaling failure, Superwall will count it as a conversion. ## Props | Name | Type | Description | Required | | ---------- | ------------------------------- | ----------------------------------------------------- | -------- | | controller | CustomPurchaseControllerContext | Object that implements purchase and restore handlers. | yes | | children | React.ReactNode | Child components wrapped by this provider. | yes | ### CustomPurchaseControllerContext | Name | Type | Description | | ----------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------ | | onPurchase | (params: OnPurchaseParams) => Promise\ | Handle a purchase and return a result or throw to signal failure. | | onPurchaseRestore | () => Promise\ | Handle restore purchases and return a result or throw to signal failure. | ### OnPurchaseParams (iOS) | Name | Type | Description | Required | | --------- | ------ | -------------------------------------- | -------- | | platform | "ios" | Platform identifier for iOS purchases. | yes | | productId | string | App Store product identifier. | yes | ### OnPurchaseParams (Android) | Name | Type | Description | Required | | ---------- | --------- | ------------------------------------------ | -------- | | platform | "android" | Platform identifier for Android purchases. | yes | | productId | string | Google Play product identifier. | yes | | basePlanId | string | Subscription base plan ID. | yes | | offerId | string? | Optional promotional offer ID. | no | ### PurchaseResult | Name | Type | Description | Required | | ----- | --------------------------------------------------- | ------------------------------------------- | -------- | | type | "cancelled" \| "failed" \| "purchased" \| "pending" | Outcome of the purchase flow. | yes | | error | string? | Optional error message when type is failed. | no | ### RestoreResult | Name | Type | Description | Required | | ----- | ---------------------- | ------------------------------------------- | -------- | | type | "restored" \| "failed" | Outcome of the restore flow. | yes | | error | string? | Optional error message when type is failed. | no | ## Hook ### `useCustomPurchaseController()` A hook that provides access to the custom purchase controller context from child components. ```tsx import { useCustomPurchaseController } from 'expo-superwall' function MyComponent() { const controller = useCustomPurchaseController() if (!controller) { // Not within a CustomPurchaseControllerProvider return null } const handlePurchase = async () => { // Access controller methods if needed } return } ``` | Name | Type | Description | | ----- | --------------------------------------- | --------------------------------------------------------------------------- | | value | CustomPurchaseControllerContext \| null | Controller object passed to the provider, or null if not within a provider. | ## How It Works The `CustomPurchaseControllerProvider` listens for purchase events from the Superwall SDK using the `useSuperwallEvents` hook internally. When a purchase or restore event occurs: 1. It calls your provided `onPurchase` or `onPurchaseRestore` method 2. After your method completes, it notifies the Superwall SDK that the purchase was successful 3. Superwall then dismisses the paywall and continues with the user flow ## Integration with RevenueCat For a complete RevenueCat integration with error handling, subscription status synchronization, and working examples, see the [Using RevenueCat](/docs/expo/guides/using-revenuecat) guide. ## Notes * The provider must wrap your app at a level where both the Superwall SDK and your purchase logic can access it * Purchase success/failure handling is automatic - you just need to perform the actual purchase --- # SuperwallError Source: https://superwall.com/docs/expo/sdk-reference/components/SuperwallError undefined `` is a component that renders its children only when Superwall configuration has failed. This component was added in v0.7.0 to help handle SDK initialization errors gracefully. The component can accept either static React nodes or a render function that receives the error message string. ## Props | Name | Type | Description | Required | | -------- | ------------------------------------------------------- | --------------------------------------------------------------- | -------- | | children | React.ReactNode \| ((error: string) => React.ReactNode) | Static UI or a render function that receives the error message. | yes | ## Example ### Static Error UI ```tsx import { SuperwallProvider, SuperwallError, SuperwallLoading, SuperwallLoaded, } from "expo-superwall"; import { View, Text, Button } from "react-native"; export default function App() { return ( Failed to load Superwall Please check your internet connection and try again. {/* Your main app content */} ); } ``` ### Dynamic Error UI with Error Message ```tsx import { SuperwallProvider, SuperwallError, SuperwallLoading, SuperwallLoaded, } from "expo-superwall"; import { View, Text, Button } from "react-native"; export default function App() { const handleRetry = () => { // Implement retry logic }; return ( {(error) => ( Failed to initialize Superwall {error}