init
`HotUpdater.init` initializes HotUpdater for manual update flows without wrapping a React component.
Usage
Use HotUpdater.init when you want a fully custom update flow and cannot, or do
not want to, wrap your root component with HotUpdater.wrap. Call it once when
your runtime considers the app ready. This API exists for apps that only need
Hot Updater initialization without a React HOC.
import { HotUpdater } from "@hot-updater/react-native";
HotUpdater.init({
baseURL: "<your-update-server-url>",
requestHeaders: {
Authorization: "Bearer <your-access-token>",
},
onError: error => {
console.error("Hot Updater failed", error);
},
});baseURL can also be resolved at runtime. The function may return a string or
a promise, and Hot Updater calls it before each update check.
HotUpdater.init({
baseURL: async () => {
return await getUpdateServerURL();
},
});After initialization, call HotUpdater.checkForUpdate() wherever your runtime
or app state says it is safe to check.
const updateInfo = await HotUpdater.checkForUpdate({
updateStrategy: "appVersion",
});
if (!updateInfo) {
return;
}
await updateInfo.updateBundle();
if (updateInfo.shouldForceUpdate) {
await HotUpdater.reload();
}Configuration Reference
| Option | Type | Required | Description |
|---|---|---|---|
baseURL | string | () => string | Promise<string> | Yes* | Your update server URL or runtime URL resolver |
resolver | HotUpdaterResolver | Yes* | Custom network operations |
requestHeaders | Record<string, string> | No | Shared headers used by update checks and app-ready notifications |
requestTimeout | number | No | Request timeout in milliseconds (default: 5000) |
onNotifyAppReady | (result) => void | No | Callback invoked after native app-ready state is read |
onError | (error) => void | No | Default error handler for initialization and update checks |
*Either baseURL or resolver must be provided (mutually exclusive).
HotUpdater.checkForUpdate({ onError }) overrides the onError handler from
HotUpdater.init for that specific update check.
When to Use init
Use HotUpdater.init when another runtime owns the root component, when you
need to initialize before rendering, or when your app has a custom shell that
does not make a root HOC convenient.
Use HotUpdater.wrap when you want Hot Updater to manage the root component
lifecycle directly, especially for automatic update checks with a fallback UI.
Related
wrap
`HotUpdater.wrap` checks for updates at the entry point, and if there is a bundle to update, it downloads the bundle and applies the update strategy.
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.