HotupdaterHot Updater
React Native API

checkForUpdate

The `checkForUpdate` function checks if there is an available update for the app by comparing the current app version and platform with the update server's bundle information.

Usage

Use checkForUpdate to verify if an update bundle is available. The function reuses the baseURL configured in HotUpdater.wrap(), and optionally allows overriding the updateStrategy.

import { HotUpdater } from "@hot-updater/react-native";

// First, configure baseURL and updateStrategy in wrap
export default HotUpdater.wrap({
  baseURL: "<your-update-server-url>",
  updateMode: "manual"
})(App);

// Use checkForUpdate - it reuses wrap's baseURL
async function checkForAppUpdate() {
  try {
    // Option 1: Use wrap's updateStrategy
    const updateInfo = await HotUpdater.checkForUpdate({
      requestHeaders: {
        Authorization: "Bearer <your-access-token>",
      },
    });

    if (!updateInfo) {
      return {
        status: "UP_TO_DATE",
      };
    }

    /**
     * You can apply updates using one of two methods:
     *
     * Method 1: Use the updateBundle() method from the updateInfo object
     * - A convenience method built into the return value from checkForUpdate
     * - Performs the same function as HotUpdater.updateBundle with all required arguments pre-filled
     */
    await updateInfo.updateBundle();

    /**
     * Method 2: Call HotUpdater.updateBundle() directly
     * - Explicitly pass the necessary values extracted from updateInfo
     */
    // await HotUpdater.updateBundle({
    //   bundleId: updateInfo.id,
    //   fileUrl: updateInfo.fileUrl,
    //   status: updateInfo.status,
    // });

    if (updateInfo.shouldForceUpdate) {
      await HotUpdater.reload();
    }
    return updateInfo;
  } catch (error) {
    console.error("Failed to check for update:", error);
    return null;
  }
}

Important: HotUpdater.wrap Required

When using checkForUpdate, you must wrap your root component with HotUpdater.wrap() and configure baseURL and updateStrategy. This is required for proper crash detection and rollback functionality.

import { HotUpdater } from "@hot-updater/react-native";
import { useEffect } from "react";

function App() {
  useEffect(() => {
    HotUpdater.checkForUpdate({
      requestHeaders: {
        Authorization: "Bearer <your-access-token>",
      },
    }).then(async (updateInfo) => {
      if (updateInfo) {
        await updateInfo.updateBundle();
        if (updateInfo.shouldForceUpdate) {
          await HotUpdater.reload();
        }
      }
    }).catch((error) => {
      console.error("Failed to check for update:", error);
    });
  }, []);

  return <YourApp />;
}

// Configure baseURL and updateStrategy in wrap
export default HotUpdater.wrap({
  baseURL: "<your-update-server-url>",
  updateMode: "manual"
})(App);

Without wrap, calling checkForUpdate will throw an error with instructions on how to fix it.

Parameters

The checkForUpdate function accepts the following optional parameters:

ParameterTypeRequiredDescription
updateStrategy"appVersion" | "fingerprint"Override the update strategy set in wrap. If not provided, uses the strategy from HotUpdater.wrap().
requestHeadersRecord<string, string>Optional headers to include in the update request.
requestTimeoutnumberRequest timeout in milliseconds (default: 5000).
onError(error: Error) => voidError callback.

The baseURL is always from HotUpdater.wrap() - it cannot be overridden in checkForUpdate.

How It Works

When you call checkForUpdate, the function uses the baseURL and updateStrategy from HotUpdater.wrap() to construct the appropriate endpoint URL:

  • For updateStrategy: "appVersion": GET {baseURL}/app-version/:platform/:appVersion/:channel/:minBundleId/:bundleId
  • For updateStrategy: "fingerprint": GET {baseURL}/fingerprint/:platform/:fingerprintHash/:channel/:minBundleId/:bundleId

For example, if you configured baseURL: "https://your-update-server.com/api/update-check" in wrap, the function automatically appends the correct path and parameters.

Return Value

The function returns an object of type UpdateInfo or null if the app is up to date.

export type UpdateStatus = "ROLLBACK" | "UPDATE";

export interface UpdateInfo {
  id: string;
  shouldForceUpdate: boolean;
  fileUrl: string | null;
  message: string | null;
  status: UpdateStatus;
}

Example Return Value

{
  "id": "01952bbd-e7b2-7931-aee8-2e2187caa0ce",
  "shouldForceUpdate": true,
  "status": "UPDATE",
  "fileUrl": "https://example.com/bundles/update.bundle",
  "message": "This is a test message",
}