Skip to content

useOTAUpdates Hook

Access OTA update state and actions from any component within the provider.

Basic Usage

tsx
import { useOTAUpdates } from '@ddedic/expo-fancy-ota-updates';

function MyComponent() {
  const { isUpdateAvailable, checkForUpdate } = useOTAUpdates();
  
  return (
    <Button 
      title="Check for Updates"
      onPress={checkForUpdate}
      disabled={!isUpdateAvailable}
    />
  );
}

Return Value

State

PropertyTypeDescription
isUpdateAvailablebooleanUpdate available to download
isDownloadingbooleanCurrently downloading
isDownloadedbooleanDownload complete, ready to apply
statusUpdateStatusCurrent status
checkErrorError | nullCheck error if any
downloadErrorError | nullDownload error if any
lastCheckDate | nullLast check timestamp

expo-updates Metadata

PropertyTypeDescription
currentUpdateIdstring | nullCurrent update ID
channelstring | nullUpdate channel
runtimeVersionstring | nullRuntime version
isEmbeddedUpdatebooleanIs embedded build

Version Data

PropertyTypeDescription
otaVersionstringVersion (e.g., "1.0.0-production.29")
otaBuildNumbernumberBuild number
otaReleaseDatestringRelease date (ISO)
otaChangelogstring[]Changelog items

Actions

MethodTypeDescription
checkForUpdate() => Promise<void>Check for updates
downloadUpdate() => Promise<void>Download update
reloadApp() => Promise<void>Reload app
simulateUpdate() => voidSimulate update (dev)

Theming

PropertyTypeDescription
themeOTAThemeCurrent theme
translationsOTATranslationsCurrent translations

UpdateStatus

typescript
type UpdateStatus = 
  | 'idle'
  | 'checking'
  | 'available'
  | 'downloading'
  | 'downloaded'
  | 'error';

Examples

Manual Check Button

tsx
function CheckButton() {
  const { checkForUpdate, status } = useOTAUpdates();
  
  return (
    <Button
      title={status === 'checking' ? 'Checking...' : 'Check for Updates'}
      onPress={checkForUpdate}
      disabled={status === 'checking'}
    />
  );
}

Download Progress

tsx
function DownloadStatus() {
  const { isDownloading, isDownloaded, downloadUpdate } = useOTAUpdates();
  
  if (isDownloading) {
    return <ActivityIndicator />;
  }
  
  if (isDownloaded) {
    return <Text>Update ready! Restart to apply.</Text>;
  }
  
  return <Button title="Download Update" onPress={downloadUpdate} />;
}

Version Display

tsx
function VersionInfo() {
  const { otaVersion, otaBuildNumber, otaReleaseDate } = useOTAUpdates();
  
  return (
    <View>
      <Text>Version: {otaVersion}</Text>
      <Text>Build: {otaBuildNumber}</Text>
      <Text>Released: {new Date(otaReleaseDate).toLocaleDateString()}</Text>
    </View>
  );
}

Error Handling

tsx
function UpdateWithError() {
  const { checkForUpdate, checkError, downloadError } = useOTAUpdates();
  
  const error = checkError || downloadError;
  
  return (
    <View>
      {error && <Text style={{ color: 'red' }}>{error.message}</Text>}
      <Button title="Check for Updates" onPress={checkForUpdate} />
    </View>
  );
}

Simulate Update (Development)

tsx
function DevTools() {
  const { simulateUpdate } = useOTAUpdates();
  
  if (!__DEV__) return null;
  
  return (
    <Button 
      title="Simulate Update (Dev Only)" 
      onPress={simulateUpdate} 
    />
  );
}

Next Steps

Released under the MIT License.