Hypertune
  • Introduction
  • Getting Started
    • Set up Hypertune
    • Next.js (App Router) quickstart
    • Next.js (Pages Router) quickstart
    • React quickstart
    • Remix quickstart
    • Gatsby quickstart
    • Vue quickstart
    • Nuxt quickstart
    • Node.js quickstart
    • React Native quickstart
    • JavaScript quickstart
    • Python quickstart
    • Rust quickstart
    • Go quickstart
    • Web quickstart
    • GraphQL quickstart
  • Example apps
    • Next.js and Vercel example app
  • Concepts
    • Architecture
    • Project
    • Schema
    • Flag lifecycle
    • Logic
    • Variables
    • Splits
    • A/B tests
    • Staged rollouts
    • Multivariate tests
    • Machine learning loops
    • Events
    • Funnels
    • Hypertune Edge
    • Reduction
    • SDKs
    • GraphQL API
    • Git-style version control
    • App configuration
  • Use Cases
    • Feature flags and A/B testing
    • Landing page optimization
    • In-app content management
    • Pricing plan management
    • Permissions, rules and limits
    • Optimizing magic numbers
    • Backend configuration
    • Product analytics
  • Integrations
    • Vercel Edge Config integration
    • Google Analytics integration
    • Segment integration
    • Webhooks
      • Creating webhooks
      • Handling webhooks
  • SDK Reference
    • Installation
    • Type-safe client generation
    • Initialization
    • Build-time logic snapshot
    • Hard-coded fallbacks
    • Local-only, offline mode
    • Hydrate from your own server
    • Wait for server initialization
    • Provide targeting attributes
    • Local, synchronous evaluation
    • Remote logging
    • Getting flag updates
    • Serverless environments
    • Vercel Edge Config
    • Custom logging
    • Shutting down
Powered by GitBook
On this page
  • 1. Install hypertune
  • 2. Set environment variables
  • 3. Generate the client
  • 4. Use the client
  • 5. (Optional) Include a build-time logic snapshot
  • That's it
  1. Getting Started

React Native quickstart

1. Install hypertune

Once you have an Expo / React Native application ready, install Hypertune's JavaScript SDK:

npm install hypertune
yarn add hypertune
pnpm add hypertune

2. Set environment variables

Define the following environment variables in your .env file:

EXPO_PUBLIC_HYPERTUNE_TOKEN=token
HYPERTUNE_FRAMEWORK=reactNative
HYPERTUNE_OUTPUT_DIRECTORY_PATH=generated

Replace token with your main project token which you can find in the Settings tab of your project.

3. Generate the client

Generate a type-safe client to access your flags by running:

npx hypertune
yarn hypertune
pnpm hypertune

4. Use the client

Create a new <AppHypertuneProvider> component that wraps the generated <HypertuneProvider> component:

import { HypertuneProvider } from "../generated/hypertune.react";

export default function AppHypertuneProvider({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <HypertuneProvider
      createSourceOptions={{
        token: process.env.EXPO_PUBLIC_HYPERTUNE_TOKEN!,
      }}
      rootArgs={{
        context: {
          environment:
            process.env.NODE_ENV === "development"
              ? "development"
              : "production",
          user: { id: "1", name: "Test", email: "hi@test.com" },
        },
      }}
    >
      {children}
    </HypertuneProvider>
  );
}

Wrap your app with the <AppHypertuneProvider> component:

import { View } from "react-native";
import AppHypertuneProvider from "./components/AppHypertuneProvider";
import ClientComponent from "./components/ClientComponent";

export default function App() {
  return (
    <AppHypertuneProvider>
      <View
        style={{
          flex: 1,
          justifyContent: "center",
          alignItems: "center",
        }}
      >
        <ClientComponent />
      </View>
    </AppHypertuneProvider>
  );
}

Then use the generated useHypertune hook:

import { Text } from "react-native";
import { useHypertune } from "../generated/hypertune.react";

export default function ClientComponent() {
  const hypertune = useHypertune();

  const exampleFlag = hypertune.exampleFlag({ fallback: false });

  return <Text>Example Flag: {String(exampleFlag)}</Text>;
}

5. (Optional) Include a build-time logic snapshot

To avoid this, you can include a snapshot of your flag logic in the generated client at build time. The SDK will instantly initialize from the snapshot first before fetching the latest flag logic from Hypertune Edge.

Add the following environment variable to your .env file:

HYPERTUNE_INCLUDE_INIT_DATA=true

Then regenerate the client.

That's it

Now you can update the logic for exampleFlag from the Hypertune UI without updating your code or waiting for a new build, deployment or app release.

To add a new flag, create it in the Hypertune UI then regenerate the client.

PreviousNode.js quickstartNextJavaScript quickstart

Last updated 6 months ago

If you try accessing a flag immediately after the app loads, you'll get your hardcoded fallback value if the SDK hasn't initialized from yet. This can result in a UI flicker or layout shift if the flag value changes when the SDK initializes.

You can keep the snapshot fresh by setting up a to regenerate the client and redeploy your app on every Hypertune commit. In this case, you don't need to initialize from Hypertune Edge at all.

Hypertune Edge
webhook