Hooks
usePlacement
A React hook that registers a placement so it can remotely trigger a paywall, gate feature access, and expose paywall-lifecycle state.
Purpose
Registers a placement so that, when it’s added to a campaign on the Superwall Dashboard, it can trigger a paywall and optionally gate access to a feature while exposing the paywall lifecycle as React state.
Signature
Parameters
Name | Type | Description |
---|---|---|
callbacks | usePlacementCallbacks? | Optional callbacks that fire at each stage of the paywall lifecycle. |
usePlacementCallbacks
Name | Type | Description |
---|---|---|
onPresent | (paywallInfo: PaywallInfo) => void | Called when a paywall is presented. |
onDismiss | (paywallInfo: PaywallInfo, result: PaywallResult) => void | Called when a paywall is dismissed. |
onSkip | (reason: PaywallSkippedReason) => void | Called when presentation is skipped (e.g., hold-out, no audience match). |
onError | (error: string) => void | Called when the paywall fails to present or another SDK error occurs. |
RegisterPlacementArgs
Name | Type | Description |
---|---|---|
placement | string | Placement name as defined on the Superwall Dashboard. |
params | Record<string, any>? | Optional parameters passed to the placement. |
feature | () => void | Function executed only if no paywall is shown (the user is allowed through). |
Returns / State
The hook returns an object with:
• registerPlacement
— (args: RegisterPlacementArgs) => Promise<void>
• state
— PaywallState
PaywallState
union:
{ status: "idle" }
{ status: "presented"; paywallInfo: PaywallInfo }
{ status: "dismissed"; result: PaywallResult }
{ status: "skipped"; reason: PaywallSkippedReason }
{ status: "error"; error: string }
Usage
See also: Present a paywall
How is this guide?