Statsig in Expo
Installation
To add support for Expo, first, add the Statsig JS client outlined here.
Once the Statsig client is installed, you can add the Expo bindings as described below:
- NPM
- Yarn
npm install @statsig/js-client @statsig/expo-bindings
yarn add @statsig/js-client @statsig/expo-bindings
Expo Specific Setup
Create a Client
Creating a Statsig client when using Expo has a slight twist when compared to pure JavaScript environments.
Because storage in Expo is async (See AsyncStorage), a warming step is required
to load any cache values from disk. This warming performs some AsyncStorage.getItem operations that block the
StatsigProviderExpo
from rendering.
Render the StatsigProvider
Once the Statsig client is created and the warming step started, we can then pass them into
the StatsigProviderExpo
component for rendering.
export function App(): JSX.Element {
return (
<StatsigProviderExpo client={myStatsigClient} cacheWarming={warming}>
{/* Render your App */}
</StatsigProviderExpo>
);
}
Hooks
All hooks are re-exported from the @statsig/react-bindings
package (See Hooks).
They can be imported through @statsig/expo-bindings
or directly through the @statsig/react-bindings
peer dependency.
import { useFeatureGate, useStatsigClient } from '@statsig/expo-bindings';