useSuperwall

Purpose

The useSuperwall hook is the core hook that provides access to the Superwall store and underlying SDK functionality. It's generally used internally by other more specific hooks like useUser and usePlacement, but can be used directly for advanced scenarios. It ensures that native event listeners are set up on first use.

Returned Values (Store State and Actions)

The hook returns an object representing the Superwall store. If a selector function is provided, it returns the selected slice of the store.

State

Prop Type
isConfigured? boolean
isLoading? boolean
listenersInitialized? boolean
configurationError? string | null
user? UserAttributes | null
subscriptionStatus? SubscriptionStatus

Actions (Functions)

Prop Type
configure? (apiKey: string, options?: PartialSuperwallOptions) => Promise
identify? (userId: string, options?: IdentifyOptions) => Promise
reset? () => Promise
registerPlacement? (placement: string, params?: Record<string, any>, handlerId?: string | null) => Promise
getPresentationResult? (placement: string, params?: Record<string, any>) => Promise
restorePurchases? () => Promise
dismiss? () => Promise
preloadAllPaywalls? () => Promise
preloadPaywalls? (placements: string[]) => Promise
setUserAttributes? (attrs: Record<string, any | null>) => Promise
getUserAttributes? () => Promise<Record<string, any>>
setLogLevel? (level: string) => Promise
setIntegrationAttributes? (attributes: IntegrationAttributes) => Promise
getIntegrationAttributes? () => Promise<Record<string, string>>
setSubscriptionStatus? (status: SubscriptionStatus) => Promise
getDeviceAttributes? () => Promise<Record<string, any>>
getEntitlements? () => Promise

Selector (Optional Parameter)

Prop Type
selector? (state: SuperwallStore) => T

UserAttributes

Prop Type
aliasId? string
appUserId? string
applicationInstalledAt? string
seed? number
[key: string]? any | null

SubscriptionStatus

Prop Type
status "UNKNOWN" | "INACTIVE" | "ACTIVE"
entitlements? Entitlement[]?

EntitlementsInfo

Prop Type
all? Entitlement[]?
active Entitlement[]
inactive Entitlement[]

RestorationResultResponse

Prop Type
result "restored" | "failed"
errorMessage? string | null

Example

(Direct Usage - Advanced)

import { useSuperwall } from 'expo-superwall';

function MyAdvancedComponent() {
  const { isConfigured, configure, setUserAttributes } = useSuperwall();

if (!isConfigured) {
    return <Text>SDK not configured yet.</Text>;
  }

const handleSetCustomAttribute = () => {
    setUserAttributes({ myCustomFlag: true });
  };

return <Button title="Set Custom Flag" onPress={handleSetCustomAttribute} />;
}

Example: Configure with Android identifiers

import { Platform } from "react-native"
import Superwall from "expo-superwall/compat"

async function configureSuperwall() {
  await Superwall.configure({
    apiKey: Platform.OS === "ios" ? IOS_KEY : ANDROID_KEY,
    options: Platform.OS === "android"
      ? { passIdentifiersToPlayStore: true }
      : undefined,
  })
}