How to migrate from v2 to v3

Requirements

  • React Native 0.85+ with the New Architecture enabled (previously 0.72)
  • iOS 15.1+ (previously iOS 11+)
  • Android minSdkVersion 24+

Step 1: Update your dependencies

Remove the v2 package, @datadome/react-native-datadome:

npm uninstall @datadome/react-native-datadome

Install the v3 package and the CoreDataDome SDK:

npm install @datadome/react-native-datadome-fetch @datadome/react-native-core-datadome

The v3 SDK does not use react-native-webview. If your application does not use it directly, remove it:

npm uninstall react-native-webview

On iOS, install the pods:

cd ios && pod install

Step 2: Create a DataDome instance

Replace the setSdkKey call with a DataDome instance. Give the client-side key to the constructor in the clientKey property.

Before:

import { DataDome } from '@datadome/react-native-datadome';

DataDome.getInstance().setSdkKey('YOUR_CLIENT_KEY');

After:

import { DataDome } from '@datadome/react-native-datadome-fetch';

const dataDome = new DataDome({ clientKey: 'YOUR_CLIENT_KEY' });

Step 3: Replace DataDomeFetch

Replace DataDomeFetch with the drop-in replacement that createDataDomeFetch returns. You do not need the datadome: true option anymore.

Before:

import { DataDomeFetch } from '@datadome/react-native-datadome';

const fetch = DataDomeFetch;

fetch('https://api.example.com/items', {
  method: 'GET',
  headers: { Accept: 'application/json' },
  datadome: true,
});

After:

import { createDataDomeFetch } from '@datadome/react-native-datadome-fetch';

const fetch = createDataDomeFetch(dataDome);

fetch('https://api.example.com/items', {
  method: 'GET',
  headers: { Accept: 'application/json' },
});

Step 4: Remove DataDomeModal

Remove the DataDomeModal component from your views. The SDK now shows the challenges with native code.

Before:

import { DataDomeModal } from '@datadome/react-native-datadome';

export default class MyApp extends Component {
  render() {
    return (
      <View style={{ flex: 1 }}>
        <DataDomeModal />
        <Text>Hello, world!</Text>
      </View>
    );
  }
}

After:

export default class MyApp extends Component {
  render() {
    return (
      <View style={{ flex: 1 }}>
        <Text>Hello, world!</Text>
      </View>
    );
  }
}

Did this page help you?