Skip to content
Dashboard

Custom Storage

By default, the SDK uses @react-native-async-storage/async-storage for internal persistence keys. If you prefer another storage engine, pass a custom adapter in config.storage.

interface DetourStorage {
getItem(key: string): Promise<string | null> | string | null;
setItem(key: string, value: string): Promise<void> | void;
removeItem?(key: string): Promise<void> | void;
}

The two adapters below cover the storage engines React Native apps use most often. Any object that matches the DetourStorage interface works, so use these as starting points for other engines.

import { createMMKV } from 'react-native-mmkv';
import { DetourProvider } from '@swmansion/react-native-detour';
const storage = createMMKV();
const mmkvAdapter = {
getItem: (key: string) => storage.getString(key) ?? null,
setItem: (key: string, value: string) => storage.set(key, value),
};
export default function App() {
return (
<DetourProvider
config={{
apiKey: '...',
appID: '...',
storage: mmkvAdapter,
}}
>
{/* Your app */}
</DetourProvider>
);
}
import * as SecureStore from 'expo-secure-store';
import { DetourProvider } from '@swmansion/react-native-detour';
const secureStoreAdapter = {
getItem: SecureStore.getItemAsync,
setItem: SecureStore.setItemAsync,
};
export default function App() {
return (
<DetourProvider
config={{
apiKey: '...',
appID: '...',
storage: secureStoreAdapter,
}}
>
{/* Your app */}
</DetourProvider>
);
}