Hooks
useSuperwallEvents
Purpose
The useSuperwallEvents hook provides a low-level way to subscribe to any native Superwall event. This is useful for advanced use cases or for events not covered by the more specific hooks. Listeners are automatically cleaned up when the component using this hook unmounts.
Parameters
callbacks?: SuperwallEventCallbacks: An object where keys are event names and values are the corresponding callback functions.SuperwallEventCallbacks: (Refer tosrc/useSuperwallEvents.tsandsrc/SuperwallExpoModule.types.tsfor a full list of subscribable events and their payload types. Common events include):onPaywallPresent?: (info: PaywallInfo) => voidonPaywallDismiss?: (info: PaywallInfo, result: PaywallResult) => voidonPaywallSkip?: (reason: PaywallSkippedReason) => voidonPaywallError?: (error: string) => voidonSubscriptionStatusChange?: (status: SubscriptionStatus) => voidonSuperwallEvent?: (eventInfo: SuperwallEventInfo) => void: For generic Superwall events.SuperwallEventInfo:{ event: SuperwallEvent, params: Record<string, any> }
onCustomPaywallAction?: (name: string) => void: When a custom action is triggered from a paywall.willDismissPaywall?: (info: PaywallInfo) => voidwillPresentPaywall?: (info: PaywallInfo) => voiddidDismissPaywall?: (info: PaywallInfo) => voiddidPresentPaywall?: (info: PaywallInfo) => voidonPaywallWillOpenURL?: (url: string) => voidonPaywallWillOpenDeepLink?: (url: string) => voidonLog?: (params: { level: LogLevel, scope: LogScope, message: string | null, info: Record<string, any> | null, error: string | null }) => voidhandlerId?: string: (Optional) If provided, some events likeonPaywallPresent,onPaywallDismiss,onPaywallSkipwill only be triggered if the event originated from aregisterPlacementcall associated with the samehandlerId. This is used internally byusePlacement.
Returned Values
This hook does not return any values (void). Its purpose is to set up and tear down event listeners.
Example
import { useSuperwallEvents } from 'expo-superwall';
function EventLogger() {
useSuperwallEvents({
onSuperwallEvent: (eventInfo) => {
console.log('Superwall Event:', eventInfo.event.event, eventInfo.params);
},
onSubscriptionStatusChange: (newStatus) => {
console.log('Subscription Status Changed:', newStatus.status);
},
onPaywallPresent: (info) => {
console.log('Paywall Presented (via useSuperwallEvents):', info.name);
}
});
}How is this guide?