Skip to content

Commit 86c9f1c

Browse files
authored
fix: add onFeatureFlags docs (#14243)
1 parent cd0a9da commit 86c9f1c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

contents/docs/integrate/feature-flags-code/_snippets/feature-flags-code-react-native.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ posthog.getFeatureFlag('key-for-your-multivariate-flag')
6060
posthog.getFeatureFlagPayload('key-for-your-multivariate-flag')
6161
```
6262

63+
### Ensuring flags are loaded before usage
64+
65+
Every time a user opens the app, we send a request in the background to fetch the feature flags that apply to that user. We store those flags in the storage.
66+
67+
This means that for most screens, the feature flags are available immediately — **except for the first time a user visits**.
68+
69+
To handle this, you can use the `onFeatureFlags` callback to wait for the feature flag request to finish:
70+
71+
```react-native
72+
posthog.onFeatureFlags((flags) => {
73+
// feature flags are guaranteed to be available at this point
74+
if (posthog.isFeatureEnabled('flag-key')) {
75+
// do something
76+
}
77+
})
78+
```
79+
6380
### Reloading flags
6481

6582
PostHog loads feature flags when instantiated and refreshes whenever methods are called that affect the flag.

0 commit comments

Comments
 (0)