Skip to main content

Provider Setup

Wrap your root component with a provider to initialize SwiftPatch. You have two options:

PatternBest for
withSwiftPatchMost apps. One line, zero boilerplate.
SwiftPatchProviderApps that need custom component ordering around the provider.

Both produce the same result: a React Context that manages updates, crash detection, and event polling.

Start with the HOC

Use withSwiftPatch unless you have a reason not to. You can switch to SwiftPatchProvider later without changing any hooks or methods.


withSwiftPatch HOC

Step 1: Zero-Config Setup

App.tsx
import { withSwiftPatch } from '@swiftpatch/react-native';

function App() {
return <YourApp />;
}

export default withSwiftPatch(App);

That's it! The SDK reads credentials from your native config.

Step 2: Add Options (Optional)

App.tsx
export default withSwiftPatch(App, {
deploymentKey: 'dk_xxx',
debug: __DEV__,
onUpdate: (update) => console.log('New deploy!', update),
});

Parameters

ParameterTypeRequiredDescription
ComponentReact.ComponentTypeYesYour root app component
configSwiftPatchUserConfigNoSDK config. Optional if credentials are in native config.

Config Options

OptionTypeDefaultDescription
deploymentKeystringfrom native configOverride deployment key
debugbooleanfalseEnable verbose logging
onUpdate(update: ReleaseInfo) => void--Callback when a new deployment is available
info

See Configuration for the full list of advanced options.


SwiftPatchProvider Component

Use this when you need control over the component tree -- for example, to wrap with error boundaries or navigation containers.

Basic Usage

App.tsx
import { SwiftPatchProvider } from '@swiftpatch/react-native';

function App() {
return (
<SwiftPatchProvider>
<YourApp />
</SwiftPatchProvider>
);
}

export default App;

Composing with Other Providers

App.tsx
import { SwiftPatchProvider } from '@swiftpatch/react-native';

function App() {
return (
<SwiftPatchProvider debug={__DEV__}>
<ThemeProvider>
<AuthProvider>
<NavigationContainer>
<RootNavigator />
</NavigationContainer>
</AuthProvider>
</ThemeProvider>
</SwiftPatchProvider>
);
}

Props

PropTypeRequiredDescription
childrenReact.ReactNodeYesYour app component tree
deploymentKeystringNoOverride deployment key
debugbooleanNoEnable verbose logging
onUpdate(update: ReleaseInfo) => voidNoCallback for new deployments
Same config, different syntax

SwiftPatchProvider accepts the same options as withSwiftPatch -- just as JSX props instead of an object.


What the Provider Does

Regardless of which pattern you use, the provider sets up five systems:

  1. State -- React Context with update metadata, config, and download progress.
  2. Native module -- Connects to the SwiftPatch native module. Supports both TurboModules and legacy bridge.
  3. Crash detection -- Calls markMounted() on first render. Rolls back after repeated crashes.
  4. Stabilization -- Promotes the bundle to "stable" after successful launches.
  5. Event polling -- Polls the native layer with adaptive intervals (3s-60s backoff). Pauses when backgrounded.

Built-in Update Modal

Both patterns include a built-in modal for the full update flow (check, download, restart). Enable it with the sdkPin option, then trigger it from any component:

import { useSwiftPatchModal } from '@swiftpatch/react-native';

function SettingsScreen() {
const { showModal } = useSwiftPatchModal();
return <Button title="Check for Updates" onPress={showModal} />;
}
info

The modal requires sdkPin to be set. See Configuration.


Common Mistake: Double Wrapping

Only wrap once

Do not nest withSwiftPatch and SwiftPatchProvider. Pick one pattern.

Wrong:

function App() {
return (
<SwiftPatchProvider>
<YourApp />
</SwiftPatchProvider>
);
}
export default withSwiftPatch(App); // Already wrapped above!

Right:

// Option A
export default withSwiftPatch(App);

// Option B
function App() {
return <SwiftPatchProvider><YourApp /></SwiftPatchProvider>;
}
export default App;

Next Steps

PageContents
ConfigurationAll SDK options
HooksuseSwiftPatch, useSwiftPatchUpdate, useSwiftPatchModal
MethodsImperative API for manual update control