Teardown
React Native SDKAdapters

Adapters

Configure storage and device adapters for the Teardown SDK.

The Teardown SDK uses adapters to abstract platform-specific functionality. You must provide both a storage adapter and a device adapter when initializing TeardownCore.

Storage Adapters

Storage adapters handle persistent data storage for sessions, device IDs, and version status.

Fast, encrypted storage using react-native-mmkv.

bun add react-native-mmkv
import { MMKVStorageAdapter } from '@teardown/react-native/adapters/mmkv';

const teardown = new TeardownCore({
  storageAdapter: new MMKVStorageAdapter(),
  // ...
});

Benefits:

  • Synchronous reads/writes
  • Encrypted by default
  • Small bundle size

AsyncStorageAdapter

Uses @react-native-async-storage for broader compatibility.

bun add @react-native-async-storage/async-storage
import { AsyncStorageAdapter } from '@teardown/react-native/adapters/async-storage';

const teardown = new TeardownCore({
  storageAdapter: new AsyncStorageAdapter(),
  // ...
});

Custom Storage Adapter

Implement the StorageAdapter abstract class:

import { StorageAdapter, SupportedStorage } from '@teardown/react-native';

class CustomStorageAdapter extends StorageAdapter {
  createStorage(storageKey: string): SupportedStorage {
    return {
      preload: () => {
        // Load data into memory if needed
      },
      getItem: (key: string) => {
        // Return value or null
        return localStorage.getItem(`${storageKey}:${key}`);
      },
      setItem: (key: string, value: string) => {
        localStorage.setItem(`${storageKey}:${key}`, value);
      },
      removeItem: (key: string) => {
        localStorage.removeItem(`${storageKey}:${key}`);
      },
      clear: () => {
        // Clear all keys for this namespace
      },
      keys: () => {
        // Return all keys
        return [];
      },
    };
  }
}

Device Adapters

Device adapters collect device and app information for identification.

ExpoDeviceAdapter

For Expo projects:

bun add expo-application expo-device
import { ExpoDeviceAdapter } from '@teardown/react-native/adapters/expo';

const teardown = new TeardownCore({
  deviceAdapter: new ExpoDeviceAdapter(),
  // ...
});

DeviceInfoAdapter

For React Native CLI projects:

bun add react-native-device-info
import { DeviceInfoAdapter } from '@teardown/react-native/adapters/device-info';

const teardown = new TeardownCore({
  deviceAdapter: new DeviceInfoAdapter(),
  // ...
});

Custom Device Adapter

Extend the DeviceInfoAdapter abstract class:

import { DeviceInfoAdapter } from '@teardown/react-native';
import type { ApplicationInfo, HardwareInfo, OSInfo } from '@teardown/react-native';

class CustomDeviceAdapter extends DeviceInfoAdapter {
  get applicationInfo(): ApplicationInfo {
    return {
      version: '1.0.0',
      buildNumber: '1',
      bundleId: 'com.example.app',
    };
  }

  get hardwareInfo(): HardwareInfo {
    return {
      deviceName: 'Custom Device',
      brand: 'Custom',
      deviceType: 'phone',
    };
  }

  get osInfo(): OSInfo {
    return {
      osName: 'iOS',
      osVersion: '17.0',
    };
  }
}

Common Configurations

Expo Project

import { TeardownCore } from '@teardown/react-native';
import { ExpoDeviceAdapter } from '@teardown/react-native/adapters/expo';
import { MMKVStorageAdapter } from '@teardown/react-native/adapters/mmkv';

export const teardown = new TeardownCore({
  org_id: 'your-org-id',
  project_id: 'your-project-id',
  api_key: 'your-api-key',
  storageAdapter: new MMKVStorageAdapter(),
  deviceAdapter: new ExpoDeviceAdapter(),
});

React Native CLI Project

import { TeardownCore } from '@teardown/react-native';
import { DeviceInfoAdapter } from '@teardown/react-native/adapters/device-info';
import { MMKVStorageAdapter } from '@teardown/react-native/adapters/mmkv';

export const teardown = new TeardownCore({
  org_id: 'your-org-id',
  project_id: 'your-project-id',
  api_key: 'your-api-key',
  storageAdapter: new MMKVStorageAdapter(),
  deviceAdapter: new DeviceInfoAdapter(),
});