Skip to main content

React Native SDK API Reference

Complete reference for all exports, types, and interfaces in @superflag-sh/react-native.
The React Native SDK has the same API as the React (web) SDK, but uses AsyncStorage instead of localStorage.

Components

SuperflagProvider

Context provider that wraps your app and manages flag state.
<SuperflagProvider clientKey="pub_..." ttlSeconds={60}>
  <App />
</SuperflagProvider>
Props:
PropTypeRequiredDefaultDescription
clientKeystringNoenv varPublic client key (pub_*)
ttlSecondsnumberNo60Cache TTL in seconds
childrenReactNodeYes-React children
Environment Variable Fallback: If clientKey is not provided, the provider looks for:
  • process.env.EXPO_PUBLIC_SUPERFLAG_CLIENT_KEY (Expo)

Hooks

useFlag

Get the value of a feature flag with type safety.
const value = useFlag<T>(name: string, fallback?: T): T | undefined
Parameters:
ParameterTypeRequiredDescription
namestringYesFlag key name
fallbackTNoDefault value if flag not found
Returns: The flag value cast to type T, or fallback if provided, or undefined. Examples:
// Boolean flag
const enabled = useFlag('feature-enabled', false)

// String flag
const theme = useFlag<string>('theme', 'light')

// Number flag
const limit = useFlag<number>('rate-limit', 100)

// JSON flag
const config = useFlag<{ api: string }>('api-config', { api: '/v1' })

useFlags

Get the current SDK state.
const state = useFlags(): SuperflagState
Returns:
FieldTypeDescription
flagsFlagsAll flags as key-value pairs
statusSuperflagStatusCurrent SDK status
readybooleanShorthand for status === 'ready'
loadingbooleanShorthand for status === 'loading'
versionnumber | nullConfig version number
etagstring | nullETag from last fetch
lastFetchedAtnumber | nullTimestamp of last fetch
errorstring | nullError message if failed
Example:
import { useFlags } from '@superflag-sh/react-native'
import { ActivityIndicator, Text, View } from 'react-native'

function MyScreen() {
  const { ready, loading, error, flags } = useFlags()

  if (loading) return <ActivityIndicator />
  if (error) return <Text>Error: {error}</Text>
  if (!ready) return <View />

  return <Text>Loaded {Object.keys(flags).length} flags</Text>
}

Types

SuperflagStatus

type SuperflagStatus = "idle" | "loading" | "ready" | "error" | "rate-limited"
StatusDescription
idleInitial state before fetching
loadingFetching flags from API
readyFlags loaded successfully
errorFailed to load flags
rate-limitedMonthly quota exceeded

SuperflagState

interface SuperflagState {
  flags: Flags
  status: SuperflagStatus
  version: number | null
  etag: string | null
  lastFetchedAt: number | null
  error: string | null
}

Flags

type Flags = Record<string, FlagValue>

interface FlagValue {
  type: "bool" | "string" | "number" | "json"
  value: boolean | string | number | object
}

SuperflagProviderProps

interface SuperflagProviderProps {
  clientKey?: string
  ttlSeconds?: number
  children: React.ReactNode
}

Constants

Cache Key

The SDK stores cached config under this AsyncStorage key:
const CACHE_KEY = "superflag:cache:v1"

Exports

All exports from @superflag-sh/react-native:
// Components
export { SuperflagProvider }

// Hooks
export { useFlag, useFlags }

// Types
export type {
  SuperflagStatus,
  SuperflagState,
  SuperflagProviderProps,
  Flags,
  FlagValue,
  FlagType
}

Differences from React (Web) SDK

The React Native SDK differs from the React SDK in these ways:
FeatureReact SDKReact Native SDK
StoragelocalStorageAsyncStorage
Custom storage prop✅ Supported❌ Not supported
Browser APIsAssumes availableChecks existence first
Bundle outputAny bundlerMust use tsc

TypeScript Usage

The SDK is fully typed. Import types alongside runtime exports:
import {
  SuperflagProvider,
  useFlag,
  useFlags,
  type SuperflagState
} from '@superflag-sh/react-native'

Next Steps