@umituz/react-native-subscription 2.13.19 → 2.13.20

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-subscription",
3
- "version": "2.13.19",
3
+ "version": "2.13.20",
4
4
  "description": "Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -6,7 +6,7 @@
6
6
  * Follows "Package Driven Design" by accepting dynamic props.
7
7
  */
8
8
 
9
- import { useState, useCallback } from "react";
9
+ import { useState, useCallback, useRef, useEffect } from "react";
10
10
  import { Alert } from "react-native";
11
11
  import { useLocalization } from "@umituz/react-native-localization";
12
12
  import { usePremium } from "./usePremium";
@@ -53,6 +53,18 @@ export function usePaywallOperations({
53
53
  const { purchasePackage, restorePurchase, closePaywall } = usePremium(userId);
54
54
  const [pendingPackage, setPendingPackage] = useState<PurchasesPackage | null>(null);
55
55
 
56
+ // Ref to always have latest purchasePackage function (avoids stale closure)
57
+ const purchasePackageRef = useRef(purchasePackage);
58
+ const onPurchaseSuccessRef = useRef(onPurchaseSuccess);
59
+
60
+ useEffect(() => {
61
+ purchasePackageRef.current = purchasePackage;
62
+ }, [purchasePackage]);
63
+
64
+ useEffect(() => {
65
+ onPurchaseSuccessRef.current = onPurchaseSuccess;
66
+ }, [onPurchaseSuccess]);
67
+
56
68
  /**
57
69
  * Check if action requires authentication
58
70
  * @returns true if authenticated, false if auth required
@@ -174,10 +186,12 @@ export function usePaywallOperations({
174
186
  const pkg = pendingPackage;
175
187
  setPendingPackage(null);
176
188
 
177
- const success = await purchasePackage(pkg);
189
+ // Use ref to get latest purchasePackage (avoids stale closure after auth)
190
+ const success = await purchasePackageRef.current(pkg);
178
191
 
179
192
  if (success) {
180
- if (onPurchaseSuccess) onPurchaseSuccess();
193
+ // Use ref to get latest callback
194
+ if (onPurchaseSuccessRef.current) onPurchaseSuccessRef.current();
181
195
  } else {
182
196
  Alert.alert(
183
197
  t("premium.purchaseError"),
@@ -186,7 +200,7 @@ export function usePaywallOperations({
186
200
  }
187
201
 
188
202
  return success;
189
- }, [pendingPackage, purchasePackage, onPurchaseSuccess, t]);
203
+ }, [pendingPackage, t]);
190
204
 
191
205
  const clearPendingPackage = useCallback(() => {
192
206
  setPendingPackage(null);