React Native + Fetch
The React Native Fetch SDK protects the requests that your React Native application sends with the Fetch API.
Since version 3.0.0, the SDK uses the CoreDataDome SDK for React Native. The CoreDataDome SDK manages the native code, the cookie storage, and the challenge display.
If you use an older version, read the migration guide to upgrade.
The documentation for previous major versions is on the v2 page and the v1 page.
Requirements
- React Native: 0.85+, with the New Architecture enabled (the default)
- iOS: deployment target 15.1+
- Android:
minSdkVersion24+
- The client-side key available in your DataDome dashboard
Installation
Add the SDK and its dependency, the CoreDataDome SDK, to your project:
npm install @datadome/react-native-datadome-fetch @datadome/react-native-core-datadomeOr, with Yarn:
yarn add @datadome/react-native-datadome-fetch @datadome/react-native-core-datadomeOn iOS, install the pods to link the native SDK:
cd ios && pod installConfiguration
Initialize the DataDome instance
DataDome instance-
Create a configuration object:
import { DataDome, type DataDomeConfiguration } from '@datadome/react-native-datadome-fetch'; const config: DataDomeConfiguration = { clientKey: 'YOUR_CLIENT_KEY', };Property Type Description clientKeystringRequired: Your DataDome client-side key. domainstring | nullOptional: The origin URL that the instance applies to, for example https://example.com. -
Create the
DataDomeinstance:const dataDome = new DataDome(config);
If you create a second DataDome instance with the same configuration, the SDK uses the same native instance again.
Create the protectedFetch function
protectedFetch functioncreateDataDomeFetch returns a drop-in replacement for the Fetch API:
import { createDataDomeFetch } from '@datadome/react-native-datadome-fetch';
const protectedFetch = createDataDomeFetch(dataDome);Usage
Use this function as you use the Fetch API:
const response = await protectedFetch('https://api.example.com/items', {
method: 'GET',
headers: { Accept: 'application/json' },
});For each request, the SDK does these steps:
- It adds headers to the request. These headers include the
datadomecookie. - It sends the request with the built-in Fetch API.
- It validates the response and saves the
datadomecookie. If DataDome challenges the request, the SDK shows the challenge to the end user (for example Slider, Device Check, or Block page). - After the end user solves the challenge, the SDK retries the request. Then it returns the response to the application.
Updated 13 days ago

