Mobile SDKs

React Native SDK (@dpdpashield/react-native-consent)

Official React Native & Expo SDK for DPDPA 2023 compliance. Features <ShieldConsent> context provider, useConsent hook, <ShieldGate> purpose gating, and offline caching.

npm install @dpdpashield/react-native-consent
View @dpdpashield/react-native-consent on NPM

Package Architecture & Capabilities

<ShieldConsent> Context Provider for Global App Tree Wrapping
useConsent() Hook for Granular Preference Retrieval & Withdrawal
<ShieldGate> Purpose Gating Component with Fail-Closed Fallback
Zero Native C++ Dependencies (Lightweight ~1.2 KB Minified)
Full Expo and Bare React Native / TypeScript Compatibility
Local-First Cache with Auto-Retry Queue for Offline Usage
1. Wrap Application with <ShieldConsent>
tsx
import React from 'react';
import { ShieldConsent } from '@dpdpashield/react-native-consent';
import { MainNavigator } from './navigation/MainNavigator';

export default function App() {
  return (
    <ShieldConsent
      apiKey="dpdpa_live_sec_mumbai_89218"
      environment="production"
      defaultLanguage="hi"
    >
      <MainNavigator />
    </ShieldConsent>
  );
}
2. Read & Toggle Consent with useConsent Hook
tsx
import React from 'react';
import { View, Text, Switch, StyleSheet } from 'react-native';
import { useConsent } from '@dpdpashield/react-native-consent';

export function PrivacySettingsScreen() {
  const { hasConsent, grantConsent, revokeConsent, isSyncing } = useConsent();

  const handleToggle = async (purposeId: string, enabled: boolean) => {
    if (enabled) {
      await grantConsent(purposeId);
    } else {
      // Section 6(4): Withdrawal must be as simple as granting
      await revokeConsent(purposeId);
    }
  };

  return (
    <View style={styles.container}>
      <Text style={styles.title}>DPDPA Privacy Preferences</Text>
      <View style={styles.row}>
        <Text>Analytics & Telemetry</Text>
        <Switch
          value={hasConsent('analytics')}
          onValueChange={(val) => handleToggle('analytics', val)}
        />
      </View>
    </View>
  );
}
3. Enforce Purpose Gating with <ShieldGate>
tsx
import React from 'react';
import { View, Text } from 'react-native';
import { ShieldGate } from '@dpdpashield/react-native-consent';
import { AnalyticsTracker } from '../components/AnalyticsTracker';

export function DashboardView() {
  return (
    <View>
      {/* Fail-closed: only mounts tracking when explicit affirmative consent exists */}
      <ShieldGate
        purposeId="analytics"
        fallback={
          <Text style={{ color: '#888' }}>Analytics telemetry paused per DPDPA preferences.</Text>
        }
      >
        <AnalyticsTracker />
      </ShieldGate>
    </View>
  );
}

Configuration Parameters

ParameterTypeDescription
apiKeystring (Required)Client SDK API key from the DPDPA Shield console.
environment'production' | 'sandbox'Endpoints default to AWS Mumbai (ap-south-1).
defaultLanguagestringDefault notice language ISO code (e.g., 'hi', 'en', 'ta').
purposeIdstring (Required for ShieldGate)Unique purpose identifier mapped to your statutory notice.

Need sandbox API keys for testing?

Create a free developer assessment account in under 60 seconds.

Get API Key