Skip to content
This repository was archived by the owner on Aug 4, 2026. It is now read-only.

Commit b13c5b8

Browse files
committed
perf(hooks): extract restorePurchases into useCallback for stable reference
1 parent 8caf60f commit b13c5b8

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/hooks/useIAP.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,15 @@ export function useIAP(options?: UseIapOptions): UseIap {
333333
[],
334334
);
335335

336-
// No local restorePurchases; use the top-level helper via returned API
336+
const restorePurchases = useCallback(async (): Promise<void> => {
337+
try {
338+
await restorePurchasesTopLevel();
339+
await getAvailablePurchasesInternal();
340+
} catch (error) {
341+
RnIapConsole.warn('Failed to restore purchases:', error);
342+
invokeOnError(error);
343+
}
344+
}, [getAvailablePurchasesInternal, invokeOnError]);
337345

338346
const validateReceipt = useCallback(
339347
async (options: VerifyPurchaseProps): Promise<VerifyPurchaseResult> =>
@@ -506,15 +514,7 @@ export function useIAP(options?: UseIapOptions): UseIap {
506514
validateReceipt,
507515
verifyPurchase,
508516
verifyPurchaseWithProvider,
509-
restorePurchases: async () => {
510-
try {
511-
await restorePurchasesTopLevel();
512-
await getAvailablePurchasesInternal();
513-
} catch (error) {
514-
RnIapConsole.warn('Failed to restore purchases:', error);
515-
invokeOnError(error);
516-
}
517-
},
517+
restorePurchases,
518518
getPromotedProductIOS,
519519
requestPurchaseOnPromotedProductIOS,
520520
getActiveSubscriptions: getActiveSubscriptionsInternal,

0 commit comments

Comments
 (0)