Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions docs/docs/api/methods/listeners.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,19 +379,14 @@ For simpler usage, consider using the `useIAP` hook which automatically manages
import {useIAP} from 'react-native-iap';

export default function StoreComponent() {
const {currentPurchase, currentPurchaseError} = useIAP();

useEffect(() => {
if (currentPurchase) {
handlePurchaseUpdate(currentPurchase);
}
}, [currentPurchase]);

useEffect(() => {
if (currentPurchaseError) {
handlePurchaseError(currentPurchaseError);
}
}, [currentPurchaseError]);
const {/* other props */} = useIAP({
onPurchaseSuccess: async (purchase) => {
await handlePurchaseUpdate(purchase);
},
onPurchaseError: (error) => {
handlePurchaseError(error);
},
});

// Rest of component
}
Expand Down
22 changes: 3 additions & 19 deletions docs/docs/api/use-iap.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import {useIAP} from 'react-native-iap';
The `useIAP` hook follows React Hooks conventions and differs from calling functions directly from `react-native-iap` (index exports):

- **Automatic connection**: Automatically calls `initConnection` on mount and `endConnection` on unmount.
- **Void-returning methods**: Methods like `fetchProducts`, `requestPurchase`, `getAvailablePurchases`, etc. return `Promise<void>` in the hook. They do not resolve to data. Instead, they update internal state exposed by the hook: `products`, `subscriptions`, `availablePurchases`, `currentPurchase`, etc.
- **Don’t await for data**: When using the hook, do not write `const x = await fetchProducts(...)`. Call the method, then read the corresponding state from the hook.
- **Prefer callbacks over `currentPurchase`**: `currentPurchase` was historically useful for debugging and migration, but for new code you should rely on `onPurchaseSuccess` and `onPurchaseError` options passed to `useIAP`.
- **Void-returning methods**: Methods like `fetchProducts`, `requestPurchase`, `getAvailablePurchases`, etc. return `Promise<void>` in the hook. They do not resolve to data. Instead, they update internal state exposed by the hook: `products`, `subscriptions`, `availablePurchases`, etc.
- **Don't await for data**: When using the hook, do not write `const x = await fetchProducts(...)`. Call the method, then read the corresponding state from the hook.

## Basic Usage

Expand All @@ -35,8 +34,6 @@ const {
products,
subscriptions,
availablePurchases,
currentPurchase, // Debugging/migration friendly; prefer callbacks
currentPurchaseError, // Debugging/migration friendly; prefer callbacks
fetchProducts,
requestPurchase,
validateReceipt,
Expand Down Expand Up @@ -144,19 +141,6 @@ interface UseIAPOptions {
));
```

#### currentPurchase

- **Type**: `Purchase | null`
- **Description**: Last purchase event captured by the hook. This value is primarily helpful for debugging and migration. For production flows, prefer handling purchase results via `onPurchaseSuccess` and errors via `onPurchaseError` passed to `useIAP`.
- **Example (debug logging only)**:

```tsx
useEffect(() => {
if (currentPurchase) {
console.log('Debug purchase event:', currentPurchase.id);
}
}, [currentPurchase]);
```

#### currentPurchaseError

Expand Down Expand Up @@ -235,7 +219,7 @@ interface UseIAPOptions {
```tsx
const buyProduct = async (productId: string) => {
try {
// In hook: returns void. Listen via callbacks or `currentPurchase`.
// In hook: returns void. Listen via callbacks.
await requestPurchase({
request: {
ios: {sku: productId},
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/examples/available-purchases.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import AdFitTopFixed from "@site/src/uis/AdFitTopFixed";

<AdFitTopFixed />

This example shows how to list and restore previously purchased items (non‑consumables and active subscriptions) using `getAvailablePurchases()` and `getActiveSubscriptions()`.
This guide demonstrates how to list and restore previously purchased items (non‑consumables and active subscriptions) using `getAvailablePurchases()` and `getActiveSubscriptions()`.

View the full example source:

- GitHub: https://github.com/hyochan/react-native-iap/blob/main/example/app/available-purchases.tsx
:::note
The complete working example can be found at [example/screens/AvailablePurchases.tsx](https://github.com/hyochan/react-native-iap/blob/main/example/screens/AvailablePurchases.tsx). Note that the example code was heavily vibe-coded with Claude and is quite verbose/messy for demonstration purposes - use it as a reference only.
:::

## Restore Flow

Expand Down
8 changes: 4 additions & 4 deletions docs/docs/examples/offer-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import AdFitTopFixed from "@site/src/uis/AdFitTopFixed";

<AdFitTopFixed />

Redeem App Store offer/promo codes using the native iOS sheet. This is useful for subscription promotional codes and requires a real iOS device.
This guide demonstrates how to redeem App Store offer/promo codes using the native iOS sheet. This is useful for subscription promotional codes and requires a real iOS device.

View the full example source:

- GitHub: https://github.com/hyochan/react-native-iap/blob/main/example/app/offer-code.tsx
:::note
The complete working example can be found at [example/screens/OfferCode.tsx](https://github.com/hyochan/react-native-iap/blob/main/example/screens/OfferCode.tsx). Note that the example code was heavily vibe-coded with Claude and is quite verbose/messy for demonstration purposes - use it as a reference only.
:::

## Usage

Expand Down
8 changes: 4 additions & 4 deletions docs/docs/examples/purchase-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import AdFitTopFixed from "@site/src/uis/AdFitTopFixed";

<AdFitTopFixed />

This example walks through a clean purchase flow using react-native-iap with the `useIAP` hook and the new platform‑specific request shape. It mirrors the working sample in `example/app/purchase-flow.tsx`.
This guide demonstrates a clean purchase flow using react-native-iap with the `useIAP` hook and the new platform‑specific request shape.

View the full example source:

- GitHub: [example/app/purchase-flow.tsx](https://github.com/hyochan/react-native-iap/blob/main/example/app/purchase-flow.tsx)
:::note
The complete working example can be found at [example/screens/PurchaseFlow.tsx](https://github.com/hyochan/react-native-iap/blob/main/example/screens/PurchaseFlow.tsx). Note that the example code was heavily vibe-coded with Claude and is quite verbose/messy for demonstration purposes - use it as a reference only.
:::

## Flow Overview

Expand Down
Loading