# 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`.

## Storage interface

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

## Examples

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.

### React Native MMKV

```ts
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>
  );
}
```

### Expo Secure Store

```ts
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>
  );
}
```

## Related pages

- [Usage](https://detour.swmansion.com/docs/sdk/react-native/sdk-usage)
- [API Reference](https://detour.swmansion.com/docs/sdk/react-native/api-reference)