How can I correctly use expo-iao to purchase iOS subscriptions? #262
-
|
I switched from react-native-iap to expo-iap, but I still don't understand how to use this library correctly. I'm sure I've read the documentation, but I haven't gotten what I want, so I have a few questions. I would be very grateful if someone could help me 🙏.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
|
@konson-git Thanks for the question! Please check below! 1. Where to implement
|
Beta Was this translation helpful? Give feedback.
-
|
@Navipro70 Your concern about race conditions with multiple The IssueEach
Recommended PatternUse a single // _layout.tsx
export default function RootLayout() {
const {
products,
subscriptions,
requestPurchase,
fetchProducts,
} = useIAP({
onPurchaseSuccess: (purchase) => {
// Centralized purchase handling
},
onPurchaseError: (error) => {
// Centralized error handling
},
});
return (
<Stack>
{/* Child screens access IAP data via props or navigation params */}
</Stack>
);
}Pass the necessary IAP state and methods down to child screens via props, navigation params, or a simple context if needed. The key point is to have only one |
Beta Was this translation helpful? Give feedback.
@konson-git Thanks for the question! Please check below!
1. Where to implement
useIAPYou can use
useIAPon any screen where you need purchase functionality:Note:
useIAPautomatically cleans up listeners when the component unmounts, so you don't need to manage it manually.You can also implement listeners globally in
_layout.tsxif you prefer centralized handling.2. Restoring purchase…