Provider Setup
Wrap your root component with a provider to initialize SwiftPatch. You have two options:
| Pattern | Best for |
|---|---|
withSwiftPatch | Most apps. One line, zero boilerplate. |
SwiftPatchProvider | Apps that need custom component ordering around the provider. |
Both produce the same result: a React Context that manages updates, crash detection, and event polling.
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
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)
export default withSwiftPatch(App, {
deploymentKey: 'dk_xxx',
debug: __DEV__,
onUpdate: (update) => console.log('New deploy!', update),
});
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
Component | React.ComponentType | Yes | Your root app component |
config | SwiftPatchUserConfig | No | SDK config. Optional if credentials are in native config. |
Config Options
| Option | Type | Default | Description |
|---|---|---|---|
deploymentKey | string | from native config | Override deployment key |
debug | boolean | false | Enable verbose logging |
onUpdate | (update: ReleaseInfo) => void | -- | Callback when a new deployment is available |
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
import { SwiftPatchProvider } from '@swiftpatch/react-native';
function App() {
return (
<SwiftPatchProvider>
<YourApp />
</SwiftPatchProvider>
);
}
export default App;
Composing with Other Providers
import { SwiftPatchProvider } from '@swiftpatch/react-native';
function App() {
return (
<SwiftPatchProvider debug={__DEV__}>
<ThemeProvider>
<AuthProvider>
<NavigationContainer>
<RootNavigator />
</NavigationContainer>
</AuthProvider>
</ThemeProvider>
</SwiftPatchProvider>
);
}
Props
| Prop | Type | Required | Description |
|---|---|---|---|
children | React.ReactNode | Yes | Your app component tree |
deploymentKey | string | No | Override deployment key |
debug | boolean | No | Enable verbose logging |
onUpdate | (update: ReleaseInfo) => void | No | Callback for new deployments |
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:
- State -- React Context with update metadata, config, and download progress.
- Native module -- Connects to the SwiftPatch native module. Supports both TurboModules and legacy bridge.
- Crash detection -- Calls
markMounted()on first render. Rolls back after repeated crashes. - Stabilization -- Promotes the bundle to "stable" after successful launches.
- 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} />;
}
The modal requires sdkPin to be set. See Configuration.
Common Mistake: Double Wrapping
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
| Page | Contents |
|---|---|
| Configuration | All SDK options |
| Hooks | useSwiftPatch, useSwiftPatchUpdate, useSwiftPatchModal |
| Methods | Imperative API for manual update control |