-
-
Save joshdholtz/3f26a6f06b86d2452d4180182876d824 to your computer and use it in GitHub Desktop.
import React, { useEffect, useState } from 'react'; | |
import { Platform, Text, View } from 'react-native'; | |
import Purchases, { PurchasesOffering } from 'react-native-purchases'; | |
const APIKeys = { | |
apple: "your_revenuecat_apple_api_key", | |
google: "your_revenuecat_google_api_key", | |
}; | |
export default function App() { | |
const [currentOffering, setCurrentOffering] = useState<PurchasesOffering | null>(null); | |
useEffect(() => { | |
const setup = async () => { | |
if (Platform.OS == "android") { | |
await Purchases.configure({ apiKey: APIKeys.google }); | |
} else { | |
await Purchases.configure({ apiKey: APIKeys.apple }); | |
} | |
const offerings = await Purchases.getOfferings(); | |
setCurrentOffering(offerings.current); | |
}; | |
Purchases.setDebugLogsEnabled(true); | |
setup() | |
.catch(console.log); | |
}, []); | |
if (!currentOffering) { | |
return "Loading..."; | |
} else { | |
return ( | |
<View> | |
<Text>Current Offering: {currentOffering.identifier}</Text> | |
<Text>Package Count: {currentOffering.availablePackages.length}</Text> | |
{ | |
currentOffering.availablePackages.map((pkg) => { | |
return <Text>{ pkg.product.identifier }</Text> | |
}) | |
} | |
</View> | |
); | |
} | |
} |
the awaits on line 22 and 24 are a problem, I moved lines 20-25 into the beginning of fetchData and it worked fine.
Hey, thanks for this example! FYI there's an error on line 22. It should be await Purchases.configure({ apiKey: APIKeys.google });
Yeah both the bugs reported by you folks are true @redcartel and @hehooleehoo
what would this look like in javascript
what would this look like in javascript
the same, except for the type after useState, which you can just ignore in javascript,
Would be very important if u put here which was version "react-native-purchases" u used.
I mean, because on the actually version "react-native-purchases": "^6.3.0" I am having problem and same with my configs OK no RevenueCat, always I have a return null or [].
Error: There is an issue with your configuration. Check the underlying error for more details. There are no products registered in the RevenueCat dashboard for your offerings. If you don't want to use the offerings system, you can safely ignore this message. To configure offerings and their products, follow the instructions in https://rev.cat/how-to-configure-offerings.
More information: https://rev.cat/why-are-offerings-empty
L26: Purchases.setLogLevel(LOG_LEVEL.DEBUG);
L26:
Purchases.setLogLevel(LOG_LEVEL.DEBUG);
I needed this: Purchases.setLogLevel(Purchases.LOG_LEVEL.DEBUG);
Purchases.configure
is handled as a promise here, but the typescript typings shows it as having a void
return type
i cant get this to work. I always get this error:
[TypeError: Cannot read property 'setupPurchases' of null]
EAS Dev Build
Same dependency installed
And still this error. Could you also provide the package.json because this is just really nothing. Maybe its versions which are not compatible.
Going to have to render line 32 as
<Text>Loading...</Text>