Skip to content

Commit

Permalink
docs: react proxy sdk: explain clientKey and other config vars.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Dec 6, 2021
1 parent d936a0d commit b46afd8
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions website/docs/sdks/proxy-react.md
Expand Up @@ -3,19 +3,45 @@ id: proxy-react
title: React proxy SDK
---

> This library is meant to be used with the [unleash-proxy](https://github.com/Unleash/unleash-proxy). The proxy application layer will sit between your unleash instance and your client applications, and provides performance and security benefits. DO NOT TRY to connect this library directly to the unleash instance, as the datasets follow different formats because the proxy only returns evaluated toggle information.
This library is meant to be used with the [unleash-proxy](https://github.com/Unleash/unleash-proxy). The proxy application layer will sit between your unleash instance and your client applications, and provides performance and security benefits. DO NOT TRY to connect this library directly to the unleash instance, as the datasets follow different formats because the proxy only returns evaluated toggle information.

# Installation
For more detailed information, check out [the React Proxy SDK on GitHub](https://github.com/Unleash/proxy-client-react).

```

## Installation

```sh
npm install @unleash/proxy-client-react
// or
yarn add @unleash/proxy-client-react
```

Import the provider like this in your entrypoint file (typically index.js/ts):
## Initialize the client

The snippet below shows you how to initialize the client. We recommend that you do this in your entry point file (typically index.js/ts) to ensure that you only have _one_ instance of it.

The configuration variables are:
- **`url`**

Your proxy's URL.
- **`clientKey`**

One of your proxy's [designated client keys (also known as proxy secrets)](unleash-proxy#configuration-variables).

- **`refreshInterval`**

```js
How often (in seconds) the client should poll the proxy for updates.

- **`appName`**

The name of your application. It's only used for identifying your application and can be whatever you want it to be.

- **`environment`**

The environment that your application runs in. This corresponds to the environment field in [the Unleash Context](../user_guide/unleash-context.md). Note that this is separate from the newer [Environments feature](../user_guide/environments.md).


```jsx
import FlagProvider from '@unleash/proxy-client-react';

const config = {
Expand All @@ -36,9 +62,11 @@ ReactDOM.render(
);
```

## How to check feature toggle states

To check if a feature is enabled:

```js
```jsx
import { useFlag } from '@unleash/proxy-client-react';

const TestComponent = () => {
Expand All @@ -55,7 +83,7 @@ export default TestComponent;

To check variants:

```js
```jsx
import { useVariant } from '@unleash/proxy-client-react';

const TestComponent = () => {
Expand All @@ -72,11 +100,11 @@ const TestComponent = () => {
export default TestComponent;
```

## Updating context
## How to update the Unleash Context

Follow the following steps in order to update the unleash context:

```js
```jsx
import { useUnleashContext, useFlag } from '@unleash/proxy-client-react'

const MyComponent = ({ userId }) => {
Expand Down

0 comments on commit b46afd8

Please sign in to comment.