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

simplify react setup docs #1921

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 2 additions & 15 deletions docs/client/javascript-mono/_reactSetup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ To use Statsig in React, you first must create an instance of the Statsig client

This will set your client as part of the [StatsigContext](https://github.com/statsig-io/js-client-monorepo/blob/main/packages/react-bindings/src/StatsigContext.ts) and make it available to all Statsig [hooks](#hooks).

### Asynchronous Initialization (Network)

When calling StatsigClient.initializeAsync, the client will load values from cache and provide them to the client. The client will then fetch the latest values from the network, providing the ability to await the latest values from Statsig.

If you want the latest values, but do not want to await the asynchronous call, you may call initializeAsync and simply .catch the promise. Note that this could lead to values changing mid-session as newer values arrive from the network.

Note: To learn more about sync vs async initialization and how it can be customized, see [Using EvaluationsDataAdapter](/client/javascript-sdk/using-evaluations-data-adapter)

### Initialize
Call `StatsigClient.initializeAsync` and wait for the result to get the most up to date values from the network.
tore-statsig marked this conversation as resolved.
Show resolved Hide resolved

```js
function Content() {
Expand Down Expand Up @@ -58,10 +52,3 @@ export default function AsyncInitializeExample(): JSX.Element {
);
}
```


### Synchronous Initialization (Cache)

When calling StatsigClient.initalizeSync, the client will attempt to use cache values if they are available. The client will also fetch new values in the background and update the cache (not the current in-use values). In practice, unless an additional update call is made, this means that for the very first session of a given user, there will be no values, and not until the next session will the cache have values.

<GitHubEmbed url="https://raw.githubusercontent.com/statsig-io/js-client-monorepo/main/samples/react/src/samples/react-precomp/sample-react-precomp-initialize.tsx" />
Loading