Skip to content

Commit 4dde7bf

Browse files
Docs/document events (#184)
1 parent 87555d1 commit 4dde7bf

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ yarn add @unleash/proxy-client-react unleash-proxy-client
88

99
# How to use
1010

11+
This library uses the core [unleash-proxy-client](https://github.com/Unleash/unleash-proxy-client-js) JS client as a base.
12+
1113
## Initialize the client
1214

15+
*NOTE*: [unleash-proxy](https://github.com/Unleash/unleash-proxy) is in maintenance mode. It is recommend to use the [Frontend API](https://docs.getunleash.io/reference/front-end-api) or [unleash-edge](https://github.com/Unleash/unleash-edge) instead.
16+
1317
Prepare [Unleash Proxy](https://docs.getunleash.io/reference/unleash-proxy) secret
1418
or [Frontend API Access](https://docs.getunleash.io/reference/front-end-api) token.
1519

@@ -42,6 +46,8 @@ root.render(
4246

4347
To connect this SDK to your Unleash instance's [front-end API](https://docs.getunleash.io/reference/front-end-api), use the URL to your Unleash instance's front-end API (`<unleash-url>/api/frontend`) as the `url` parameter. For the `clientKey` parameter, use a `FRONTEND` token generated from your Unleash instance. Refer to the [_how to create API tokens_](https://docs.getunleash.io/how-to/how-to-create-api-tokens) guide for the necessary steps.
4448

49+
To connect this SDK to unleash-edge, follow the documentation provided in the [unleash-edge repository](https://github.com/unleash/unleash-edge).
50+
4551
To connect this SDK to the [Unleash proxy](https://docs.getunleash.io/reference/unleash-proxy), use the proxy's URL and a [proxy client key](https://docs.getunleash.io/reference/api-tokens-and-client-keys#proxy-client-keys). The [_configuration_ section of the Unleash proxy docs](https://docs.getunleash.io/reference/unleash-proxy#configuration) contains more info on how to configure client keys for your proxy.
4652

4753
## Check feature toggle status
@@ -134,6 +140,36 @@ const MyComponent = ({ userId }) => {
134140
};
135141
```
136142

143+
## Listening to events
144+
145+
The core JavaScript client emits various types of events depending on internal activities. You can listen to these events by using a hook to access the client and then directly attaching event listeners. Alternatively, if you're using the FlagProvider with a client, you can directly use this client to listen to the events. [See the full list of events here.](https://github.com/Unleash/unleash-proxy-client-js?tab=readme-ov-file#available-events)
146+
147+
NOTE: `FlagProvider` uses these internal events to provide information through `useFlagsStatus`.
148+
149+
```jsx
150+
import { useUnleashContext, useFlag } from '@unleash/proxy-client-react';
151+
152+
const MyComponent = ({ userId }) => {
153+
const client = useUnleashClient();
154+
155+
useEffect(() => {
156+
if (client) {
157+
const handleError = () => {
158+
// Handle error
159+
}
160+
161+
client.on('error', handleError)
162+
}
163+
164+
return () => {
165+
client.off('error', handleError)
166+
}
167+
}, [client])
168+
169+
// ...rest of component
170+
};
171+
```
172+
137173
# Advanced use cases
138174

139175
## Deferring client start

0 commit comments

Comments
 (0)