@superwall/paywalls-react 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +109 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # @superwall/paywalls-react
2
+
3
+ React 19 bindings for the Superwall web SDK — a provider + hooks over
4
+ [`@superwall/paywalls-js`](https://www.npmjs.com/package/@superwall/paywalls-js).
5
+
6
+ ```sh
7
+ bun add @superwall/paywalls-react # or npm / pnpm / yarn
8
+ ```
9
+
10
+ ## Quick start
11
+
12
+ Wrap your app once:
13
+
14
+ ```tsx
15
+ import { SuperwallProvider } from "@superwall/paywalls-react";
16
+
17
+ export function Root() {
18
+ return (
19
+ <SuperwallProvider apiKey="pk_your_public_key">
20
+ <App />
21
+ </SuperwallProvider>
22
+ );
23
+ }
24
+ ```
25
+
26
+ `SuperwallProvider` takes the same config as `createSuperwall`
27
+ (`apiKey`, `storage`, `delegate`, `identity`, `options`).
28
+
29
+ ## Placements
30
+
31
+ ```tsx
32
+ import { usePlacement } from "@superwall/paywalls-react";
33
+
34
+ function GoPro() {
35
+ const { register, state } = usePlacement({
36
+ onPresent: (info) => {},
37
+ onDismiss: (info, result) => {},
38
+ onSkip: (reason) => {},
39
+ });
40
+
41
+ return (
42
+ <button onClick={() => register({ placement: "campaign_trigger" })}>
43
+ Go Pro {state.type === "presented" && "(open)"}
44
+ </button>
45
+ );
46
+ }
47
+ ```
48
+
49
+ ### Feature block
50
+
51
+ Pass a `feature` callback to run code when the user is entitled to access the
52
+ feature — i.e. already subscribed, or after a successful purchase/restore.
53
+ Mirrors the feature block in Superwall's native SDKs.
54
+
55
+ ```tsx
56
+ function GoPro() {
57
+ const { register, state } = usePlacement();
58
+
59
+ return (
60
+ <button
61
+ onClick={() =>
62
+ register({
63
+ placement: "campaign_trigger",
64
+ feature: () => router.push("/pro-content"),
65
+ })
66
+ }
67
+ >
68
+ Go Pro {state.type === "presented" && "(open)"}
69
+ </button>
70
+ );
71
+ }
72
+ ```
73
+
74
+ `feature()` fires when:
75
+ - The user is already subscribed — paywall is skipped and the feature runs immediately
76
+ - The placement has no audience match / holdout — feature runs without showing a paywall
77
+ - The user completes a purchase or restore through the paywall
78
+
79
+ ## Subscription status & user
80
+
81
+ ```tsx
82
+ import { useUser } from "@superwall/paywalls-react";
83
+
84
+ function Status() {
85
+ const { id, isLoggedIn, subscriptionStatus, entitlements, identify, signOut } =
86
+ useUser();
87
+
88
+ if (subscriptionStatus.status === "ACTIVE") return <Pro />;
89
+ return <button onClick={() => identify("app_user_123")}>Log in</button>;
90
+ }
91
+ ```
92
+
93
+ ## Hooks
94
+
95
+ | Hook | What it gives you |
96
+ |------|-------------------|
97
+ | `useSuperwall()` | the raw `Superwall` instance |
98
+ | `usePlacement(handler?)` | `{ register, state }` |
99
+ | `useUser()` | reactive identity + subscription + `identify`/`signOut`/`setAttributes` |
100
+ | `useSignal(signal)` | subscribe to any SDK `Readable<T>` |
101
+ | `useSuperwallEvent(name, fn)` | typed event listener, auto-cleanup |
102
+ | `useDelegate(delegate)` | install [delegate callbacks](https://www.npmjs.com/package/@superwall/paywalls-js#delegate-methods) for the component's lifetime |
103
+
104
+ All of `@superwall/paywalls-js` is re-exported, so you don't need to depend on
105
+ both packages directly.
106
+
107
+ ## License
108
+
109
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superwall/paywalls-react",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "exports": {
@@ -17,10 +17,10 @@
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": "^19.0.0",
20
- "@superwall/paywalls-js": "0.1.1"
20
+ "@superwall/paywalls-js": "^0.1.3"
21
21
  },
22
22
  "dependencies": {
23
- "@superwall/paywalls-js": "0.1.1"
23
+ "@superwall/paywalls-js": "^0.1.3"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@happy-dom/global-registrator": "^20.0.0",