Teardown

Getting Started

Install and configure the Teardown SDK for React Native.

Installation

Install the core package:

bun add @teardown/react-native
# or
npm install @teardown/react-native
# or
yarn add @teardown/react-native

Peer Dependencies

Choose adapters based on your project setup:

Expo projects:

npx expo install expo-device expo-application

Bare React Native projects:

npm install react-native-device-info

Storage (choose one):

# MMKV (recommended - faster, synchronous)
npm install react-native-mmkv

# or AsyncStorage (broader compatibility)
npm install @react-native-async-storage/async-storage

Getting Your Credentials

  1. Sign up or log in at dash.teardown.dev
  2. Create or select a project
  3. Copy your org_id, project_id, and api_key from project settings

Setup

1. Create SDK Configuration

Create a file to initialize the Teardown SDK (e.g., lib/teardown.ts):

Expo Setup:

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(),
});

Bare React Native Setup:

import { TeardownCore } from '@teardown/react-native';
import { DeviceInfoAdapter } from '@teardown/react-native/adapters/device-info';
import { AsyncStorageAdapter } from '@teardown/react-native/adapters/async-storage';

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

2. Wrap Your App

In your root layout file (e.g., app/_layout.tsx for Expo Router):

import { TeardownProvider } from '@teardown/react-native';
import { teardown } from '../lib/teardown';

export default function RootLayout() {
  return (
    <TeardownProvider core={teardown}>
      <YourApp />
    </TeardownProvider>
  );
}

3. Use in Components

import { useTeardown, useSession, useForceUpdate } from '@teardown/react-native';

function MyComponent() {
  const { core } = useTeardown();
  const session = useSession();
  const { isUpdateRequired } = useForceUpdate();

  const handleLogin = async () => {
    const result = await core.identity.identify({
      user_id: 'user-123',
      email: 'user@example.com',
    });

    if (result.success) {
      console.log('Session:', result.data.session_id);
    }
  };

  if (isUpdateRequired) {
    return <UpdateRequiredScreen />;
  }

  return <Button onPress={handleLogin} title="Login" />;
}

Configuration Options

TeardownCore Options

OptionTypeRequiredDescription
org_idstringYesOrganization ID from dashboard
project_idstringYesProject ID from dashboard
api_keystringYesAPI key from dashboard
storageAdapterStorageAdapterYesStorage adapter instance (see storage)
deviceAdapterDeviceInfoAdapterYesDevice info adapter (see device)
forceUpdateobjectNoForce update configuration (see force-updates)

Available Adapters

AdapterImport PathUse Case
ExpoDeviceAdapter@teardown/react-native/adapters/expoExpo projects
DeviceInfoAdapter@teardown/react-native/adapters/device-infoBare RN projects
MMKVStorageAdapter@teardown/react-native/adapters/mmkvFast sync storage
AsyncStorageAdapter@teardown/react-native/adapters/async-storageStandard async storage

Next Steps