how to use in multi component #132
Unanswered
WinnieS0728
asked this question in
Q&A
Replies: 1 comment 1 reply
-
You're slightly misunderstanding how this should work. According to the docs, the key point is: 🛑 Connection Management Issues❌ Don't initialize the connection repeatedly: // Wrong - don't initialize for every operation
const purchaseProduct = async (sku) => {
await initConnection(); // Don't do this
await requestPurchase({ sku });
await endConnection(); // Don't do this
}; ✅ Maintain a single connection throughout the app lifecycle: // Correct - use existing connection
const purchaseProduct = async (sku) => {
if (connected) {
await requestPurchase({ sku });
} else {
console.error('Store not connected');
}
}; ✅ Recommended UsageUsing You don't need to create a global IAPProvider unless you want to share the same context or data across many components. 💡 IntentAvoid initializing the connection for every action — instead, establish it once and reuse it safely across the app. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
according to doc.
we should not use
initConnection
in multi place.but
useIAP
will triggerinitConnection
multi screen
if I have
ProductScreen
andVIPScreen
.I can buy products in ProductScreen and subscribe VIP in VIPScreen.
should I use
useIAP
in both screen.or should I create a IAPProvider and initial once and pass everything down to Screen.
if I use
useIAP
in both screen, will it trigger initConnection twice?witch is suggest not to do in doc.
different component
what if we use
requestProducts
to renderProductList
but use
requestPurchase
in product card.can someone explain how to use this tool in multi place?
Beta Was this translation helpful? Give feedback.
All reactions