@silicon.js/app-updates
Version:
lightweight react package for checking app updates from ios app store and android play store using react context
86 lines (67 loc) • 3.46 kB
Markdown
# App Updates Package
A React Native package for checking app version updates from iOS App Store and Android Play Store using React Context.
## Usage Example
Wrap your root with `AppUpdatesProvider`:
```tsx
import React from 'react';
import { AppUpdatesProvider, useAppUpdates } from '@silicon.js/app-updates';
import { Platform } from 'react-native';
export default function App() {
const appUpdatesMethods = useAppUpdates({
currentVersion: '1.0.0',
appId: Platform.OS === 'ios' ? 'com.yourcompany.yourapp' : 'com.yourcompany.yourapp',
platform: Platform.OS,
autoCheck: true,
countryCode: 'us', // optional, for iOS App Store
});
return (
<AppUpdatesProvider methods={appUpdatesMethods}>
{/* other providers */}
{/* app screens here */}
</AppUpdatesProvider>
);
}
```
Use app updates context anywhere in your app:
```tsx
import { useAppUpdatesContext } from '@silicon.js/app-updates';
const DemoScreen = () => {
const { details, checkVersion } = useAppUpdatesContext();
return (
<>
{details.isNewVersionAvailable && (
<View>
<Text>New version {details.latestVersion} is available!</Text>
<Button onPress={checkVersion} title="Check Again" />
</View>
)}
{details.isChecking && <Text>Checking for updates...</Text>}
{details.error && <Text>Error: {details.error}</Text>}
</>
);
};
```
## API Reference
### useAppUpdates Hook
| Property | Type | Required | Description |
| -------------- | ------------------- | -------- | ---------------------------------------------- |
| currentVersion | string | yes | current app version (e.g., '1.0.0') |
| appId | string | yes | bundle ID (iOS) or package name (Android) |
| platform | 'ios' \| 'android' | yes | target platform |
| autoCheck | boolean | no | automatically check on mount (default: true) |
| countryCode | string | no | country code for iOS App Store (default: 'us') |
### useAppUpdatesContext Hook
Returns an object with:
| Property | Type | Description |
| --------------------- | ----------------------- | ---------------------------------------------- |
| details | AppUpdatesInfo | app updates information object |
| checkVersion | () => Promise\<void\> | manually trigger version check |
### AppUpdatesInfo Interface
| Property | Type | Description |
| --------------------- | ----------------------- | ---------------------------------------------- |
| currentVersion | string | current app version |
| latestVersion | string \| null | latest version from store |
| isNewVersionAvailable | boolean | whether a new version is available |
| isChecking | boolean | whether version check is in progress |
| lastChecked | Date \| null | timestamp of last version check |
| error | string \| null | error message if check failed |