Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loading in RN #2431

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The <div> element is not available in React Native. Please use React Native's built-in components like <Text> or <View> instead. For example:

const loadingComponent = <Text>Loading...</Text>;

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.


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>

Loading