You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{/* children here are shown when loading finishes */}
118
130
</LoadingReflag>
119
131
</ReflagProvider>
120
132
```
121
133
134
+
> [!Important]
135
+
> The `user`, `company`, and `otherContext` props are deprecated. Use the `context` prop instead, which provides the same functionality in a more structured way.
136
+
137
+
### Context requirements
138
+
139
+
If you supply `user` or `company` objects, they must include at least the `id` property otherwise they will be ignored in their entirety.
140
+
In addition to the `id`, you must also supply anything additional that you want to be able to evaluate flag targeting rules against.
141
+
Attributes which are not properties of the `user` or `company` can be supplied using the `other` property.
142
+
143
+
Attributes cannot be nested (multiple levels) and must be either strings, numbers or booleans.
144
+
A number of special attributes exist:
145
+
146
+
-`name` -- display name for `user`/`company`,
147
+
-`email` -- the email of the user,
148
+
-`avatar` -- the URL for `user`/`company` avatar image.
149
+
122
150
To retrieve flags along with their targeting information, use `useFlag(key: string)` hook (described in a section below).
123
151
124
152
Note that accessing `isEnabled` on the object returned by `useFlag()` automatically
@@ -409,12 +437,53 @@ export function HuddleFeature() {
409
437
410
438
This App Router approach leverages Server Components for server-side flag fetching while using Client Components only where React state and hooks are needed.
411
439
440
+
## `<ReflagClientProvider>` component
441
+
442
+
The `<ReflagClientProvider>` is a lower-level component that accepts a pre-initialized `ReflagClient` instance. This is useful for advanced use cases where you need full control over client initialization or want to share a client instance across multiple parts of your application.
The `ReflagClientProvider` accepts the following props:
473
+
474
+
-`client`: A pre-initialized `ReflagClient` instance
475
+
-`loadingComponent`: Optional React component to show while the client is initializing (same as `ReflagProvider`)
476
+
477
+
> [!Note]
478
+
> Most applications should use `ReflagProvider` or `ReflagBootstrappedProvider` instead of `ReflagClientProvider`. Only use this component when you need the advanced control it provides.
479
+
412
480
## `<ReflagProvider>` component
413
481
414
482
The `<ReflagProvider>` initializes the Reflag SDK, fetches flags and starts listening for automated feedback survey events. The component can be configured using a number of props:
415
483
416
484
-`publishableKey` is used to connect the provider to an _environment_ on Reflag. Find your `publishableKey` under [environment settings](https://app.reflag.com/env-current/settings/app-environments) in Reflag,
417
-
-`company`, `user` and `other` make up the _context_ that is used to determine if a flag is enabled or not. `company` and `user` contexts are automatically transmitted to Reflag servers so the Reflag app can show you which companies have access to which flags etc.
485
+
-`context` (recommended): An object containing `user`, `company`, and `other` properties that make up the evaluation context used to determine if a flag is enabled or not. `company` and `user` contexts are automatically transmitted to Reflag servers so the Reflag app can show you which companies have access to which flags etc.
486
+
-`company`, `user` and `other` (deprecated): Individual props for context. These are deprecated in favor of the `context` prop and will be removed in the next major version.
418
487
> [!Note]
419
488
> If you specify `company` and/or `user` they must have at least the `id` property, otherwise they will be ignored in their entirety. You should also supply anything additional you want to be able to evaluate flag targeting against,
420
489
-`fallbackFlags`: A list of strings which specify which flags to consider enabled if the SDK is unable to fetch flags. Can be provided in two formats:
@@ -476,7 +545,7 @@ The `<ReflagBootstrappedProvider>` is a specialized version of the `ReflagProvid
476
545
The component accepts the following props:
477
546
478
547
- `flags`: Pre-fetched flags data of type `BootstrappedFlags` obtained from the Node SDK's `getFlagsForBootstrap()` method. This contains both the context (user, company, other) and the flags data.
479
-
- All other props available in [`ReflagProvider`](#reflagprovider-component) are supported except `user`, `company`, and `other` (which are extracted from `flags.context`).
548
+
- All other props available in [`ReflagProvider`](#reflagprovider-component) are supported except `context`, `user`, `company`, and `other` (which are extracted from `flags.context`).
480
549
481
550
**Example:**
482
551
@@ -505,7 +574,7 @@ function App({ bootstrapData }: AppProps) {
505
574
```
506
575
507
576
> [!Note]
508
-
> When using `ReflagBootstrappedProvider`, the user, company, and other are extracted from the `flags.context` property and don't need to be passed separately.
577
+
> When using `ReflagBootstrappedProvider`, the context (user, company, and other) is extracted from the `flags.context` property and doesn't need to be passed separately.
509
578
510
579
## Hooks
511
580
@@ -682,8 +751,6 @@ function FlagOptIn() {
682
751
}
683
752
```
684
753
685
-
Note: To change the `user.id` or `company.id`, you need to update the props passed to `ReflagProvider` instead of using these hooks.
686
-
687
754
### `useClient()`
688
755
689
756
Returns the `ReflagClient` used by the `ReflagProvider`. The client offers more functionality that
> The `user`, `company`, and `otherContext` props are deprecated. Use the `context` prop instead, which provides the same functionality in a more structured way.
124
+
125
+
### Context requirements
126
+
127
+
If you supply `user` or `company` objects, they must include at least the `id` property otherwise they will be ignored in their entirety.
128
+
In addition to the `id`, you must also supply anything additional that you want to be able to evaluate flag targeting rules against.
129
+
Attributes which are not properties of the `user` or `company` can be supplied using the `other` property.
130
+
131
+
Attributes cannot be nested (multiple levels) and must be either strings, numbers or booleans.
132
+
A number of special attributes exist:
133
+
134
+
-`name` -- display name for `user`/`company`,
135
+
-`email` -- the email of the user,
136
+
-`avatar` -- the URL for `user`/`company` avatar image.
137
+
107
138
To retrieve flags along with their targeting information, use `useFlag(key: string)` hook (described in a section below).
108
139
109
140
Note that accessing `isEnabled` on the object returned by `useFlag()` automatically
@@ -139,7 +170,8 @@ generates a `check` event.
139
170
The `<ReflagProvider>` initializes the Reflag SDK, fetches flags and starts listening for automated feedback survey events. The component can be configured using a number of props:
140
171
141
172
-`publishableKey` is used to connect the provider to an _environment_ on Reflag. Find your `publishableKey` under [environment settings](https://app.reflag.com/env-current/settings/app-environments) in Reflag,
142
-
-`company`, `user` and `otherContext` make up the _context_ that is used to determine if a flag is enabled or not. `company` and `user` contexts are automatically transmitted to Reflag servers so the Reflag app can show you which companies have access to which flags etc.
173
+
-`context`: An object containing `user`, `company`, and `other` properties that make up the evaluation context used to determine if a flag is enabled or not. `company` and `user` contexts are automatically transmitted to Reflag servers so the Reflag app can show you which companies have access to which flags etc.
174
+
-`company`, `user` and `otherContext` (deprecated): Individual props for context. These are deprecated in favor of the `context` prop and will be removed in the next major version.
143
175
144
176
> [!Note]
145
177
> If you specify `company` and/or `user` they must have at least the `id` property, otherwise they will be ignored in their entirety. You should also supply anything additional you want to be able to evaluate flag targeting against,
`ReflagBootstrappedProvider` accepts all the same props as `ReflagProvider` except:
244
276
245
-
-`timeoutMs`, `staleWhileRevalidate`, `staleTimeMs`, `expireTimeMs` are not applicable since no requests to fetch flags are made
246
277
-`flags`: The pre-fetched flags object containing context and flag data
278
+
- All other props available in `ReflagProvider` are supported except `context`, `user`, `company`, and `otherContext` (which are extracted from `flags.context`)
247
279
248
280
If the `flags` prop is not provided or is undefined, the provider will not initialize the client and will render in a non-loading state.
249
281
282
+
## `<ReflagClientProvider>` component
283
+
284
+
The `<ReflagClientProvider>` is a lower-level component that accepts a pre-initialized `ReflagClient` instance. This is useful for advanced use cases where you need full control over client initialization or want to share a client instance across multiple parts of your application.
285
+
286
+
### ReflagClientProvider Usage
287
+
288
+
```vue
289
+
<script setup lang="ts">
290
+
import { ReflagClient } from "@reflag/browser-sdk";
291
+
import { ReflagClientProvider } from "@reflag/vue-sdk";
292
+
293
+
// Initialize the client yourself
294
+
const client = new ReflagClient({
295
+
publishableKey: "your-publishable-key",
296
+
user: { id: "user123", name: "John Doe" },
297
+
company: { id: "company456", name: "Acme Inc" },
298
+
// ... other configuration options
299
+
});
300
+
301
+
// Initialize the client
302
+
await client.initialize();
303
+
</script>
304
+
305
+
<template>
306
+
<ReflagClientProvider :client="client">
307
+
<template #loading>Loading...</template>
308
+
<Router />
309
+
</ReflagClientProvider>
310
+
</template>
311
+
```
312
+
313
+
### ReflagClientProvider Props
314
+
315
+
The `ReflagClientProvider` accepts the following props:
316
+
317
+
-`client`: A pre-initialized `ReflagClient` instance
318
+
319
+
### Slots
320
+
321
+
-`loading`: Optional slot to show while the client is initializing (same as `ReflagProvider`)
322
+
323
+
> [!Note]
324
+
> Most applications should use `ReflagProvider` or `ReflagBootstrappedProvider` instead of `ReflagClientProvider`. Only use this component when you need the advanced control it provides.
0 commit comments