Skip to content

Commit

Permalink
loading in RN
Browse files Browse the repository at this point in the history
  • Loading branch information
brock-statsig committed Dec 23, 2024
1 parent 212a7c9 commit c801293
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/client/javascript-mono/_reactNativeAdvanced.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### StatsigClient Outside the Component Tree

In some scenarios, you may need to use the `StatsigClient` when you are not in the React component tree. Things like background tasks or handling notifications.
For these, you can use the Expo specific `StatsigClientRN`.
For these, you can use the RN-specific `StatsigClientRN`.

```typescript
import { StatsigClientRN } from '@statsig/react-native-bindings';
Expand Down
58 changes: 58 additions & 0 deletions docs/client/javascript-mono/_reactNativeLoadingState.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";


## Loading State

Dependent on your setup, you may want to wait for the latest values before checking a gate or experiment.
If you are using the `StatsigProviderRN`, you can pass in a `loadingComponent` prop to display a loading state while the SDK is initializing.
If you are using the `useClientAsyncInitRN` hook, you can check the `isLoading` prop to determine if the SDK is still loading.


<Tabs
defaultValue="provider"
groupId="react-usage-choice"
values={[
{label: 'StatsigProviderRN', value: 'provider'},
{label: 'useClientAsyncInitRN', value: 'client'},
]}>

<TabItem value="provider">

```tsx
export function App() {
const loadingComponent = <div>Loading...</div>;

return (
<StatsigProviderRN
...
loadingComponent={loadingComponent} // <- Pass in the loading component
>
<YourComponent />
</StatsigProviderRN>
);
}
```

</TabItem>
<TabItem value="client">

```tsx
export function App() {
const { client, isLoading } = useClientAsyncInitRN(...);

if (isLoading) {
return <div>Loading...</div>;
}

return (
<StatsigProviderRN client={client}>
<YourComponent />
</StatsigProviderRN>
);
}
```

</TabItem>
</Tabs>

0 comments on commit c801293

Please sign in to comment.