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
{{ message }}
Repository navigation
Commit db4af1e
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: .changeset/quiet-flag-value-updates.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,6 @@
3
3
"@reflag/react-sdk": minor
4
4
---
5
5
6
-
Add a per-flag `flagUpdated` event that fires only when the effective enabled/config value or flag presence changes. Include local overrides and config key/payload changes; ignore targeting/config versions, diagnostics, and opt-in metadata. The payload is `{ key, flag }`, with `flag` undefined on removal. Keep `flagsUpdated` unchanged for raw-data subscribers.
6
+
Add a per-flag `flagUpdated` event that publishes each initial flag value during initialization, including bootstrapped flags after applying cached overrides. Subsequent events fire only when the effective enabled/config value or flag presence changes. Include local overrides and config key/payload changes; ignore targeting/config versions, diagnostics, and opt-in metadata. The payload is `{ key, flag }`, with `flag` undefined on removal. Keep `flagsUpdated` unchanged for raw-data subscribers.
7
7
8
8
Subscribe React `useFlag()` to updates for its own key so unrelated flag updates and metadata-only changes do not trigger rerenders. Continue reporting the latest evaluation metadata when consumers read enabled/config values.
Event listeners allow for capturing various events occurring in the `ReflagClient`. This is useful to build integrations with other system or for various debugging purposes. The available events are:
522
-
523
-
-`check`: Your code used `isEnabled` or `config` for a flag
524
-
-`flagsUpdated`: Raw flag data changed, including targeting/config versions, evaluation diagnostics, and opt-in metadata
525
-
-`flagUpdated`: An individual flag's effective `isEnabled` (including local overrides) or config key/payload changed, or that flag was added/removed. Metadata-only changes do not emit this event. The payload is `{ key, flag }`, with `flag` undefined on removal
526
-
-`optInFlagsLoadingUpdated`: The opt-in flag loading state changed
527
-
-`user`: User information updated (similar to the `identify` call used in tracking terminology)
528
-
-`company`: Company information updated (sometimes to the `group` call used in tracking terminology)
529
-
-`track`: Track event occurred.
530
-
531
-
Use the `on()` method to add an event listener to respond to certain events. See the API reference for details on each hook.
521
+
For most integrations, subscribe to `flagUpdated` to receive initial flag values and react to subsequent value changes. Use `on()` to register a listener:
//use the returned function to unsubscribe, or call `off()` with the same arguments again
534
+
//Register before initializing to receive initial values, including bootstrapped flags.
535
+
awaitclient.initialize();
536
+
537
+
// When disposing the integration, unsubscribe using the returned function,
538
+
// or call `off()` with the same event and handler.
545
539
unsub();
546
540
```
547
541
548
-
For integrations that only need value changes, subscribe to `flagUpdated` instead of `flagsUpdated`:
542
+
`flagUpdated` publishes an initial value for each flag during initialization. After that, it fires only when a flag's effective enabled value (including local overrides), config key/payload, or presence changes. Targeting/config versions, evaluation diagnostics, and opt-in metadata alone do not trigger subsequent events. The payload is `{ key, flag }`, with `flag` undefined on removal.
543
+
544
+
The `flag` field has the same raw shape as `getFlags()`; when present, its effective enabled value is `flag.isEnabledOverride ?? flag.isEnabled`. Accessing the event payload does not generate check telemetry.
545
+
546
+
Subscribe before calling `initialize()` to receive one initial event per flag, including disabled flags and bootstrapped flags. Bootstrapped flags are available immediately through `getFlags()`; their initial events are published during initialization after applying cached overrides, without fetching. Subscribers registered after initialization do not receive a replay.
547
+
548
+
Explicit silent updates (`updateFlags(flags, false)`) update the baseline without emitting events. Handle the `user` and `company` events separately if your integration needs to resynchronize traits when identity changes but flag values stay the same.
549
+
550
+
### Observing refreshed raw flag data
551
+
552
+
Use `flagsUpdated` when you need to observe raw flag updates, including refreshes where enabled/config values stay the same. It delivers the full flag map and also fires for targeting/config version, evaluation diagnostic, or opt-in metadata changes:
549
553
550
554
```ts
551
-
client.on("flagUpdated", ({ key, flag }) => {
552
-
console.log(key, flag);
555
+
client.on("flagsUpdated", (flags) => {
556
+
console.log(flags);
553
557
});
554
558
```
555
559
556
-
There is one event per changed flag, not a notification for all flags. The `flag` field has the same raw shape as `getFlags()`; its effective enabled value is `flag.isEnabledOverride ?? flag.isEnabled`. Accessing the event payload does not generate check telemetry.
560
+
A refresh returning identical raw flag data does not emit this event.
557
561
558
-
Initially fetched flags emit an event for each added flag. Bootstrapped flags are available immediately through `getFlags()` and do not replay events to new subscribers. Explicit silent updates (`updateFlags(flags, false)`) update the baseline without emitting events. Handle the `user` and `company` events separately if your integration needs to resynchronize traits when identity changes but flag values stay the same.
562
+
### Other events
563
+
564
+
-`check`: Your code used `isEnabled` or `config` for a flag
565
+
-`optInFlagsLoadingUpdated`: The opt-in flag loading state changed
566
+
-`user`: User information updated (similar to the `identify` call used in tracking terminology)
567
+
-`company`: Company information updated (sometimes to the `group` call used in tracking terminology)
Copy file name to clipboardExpand all lines: packages/react-sdk/README.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -914,9 +914,7 @@ function LoadingWrapper({ children }: { children: ReactNode }) {
914
914
915
915
### `useOnEvent()`
916
916
917
-
Attach a callback handler to client events to act on changes. It automatically disposes itself on unmount.
918
-
919
-
Use `flagUpdated` for individual flag value changes, including effective local overrides. Targeting/config versions, evaluation diagnostics, and opt-in metadata alone do not trigger it. Use `flagsUpdated` if you need raw flag data and metadata changes.
917
+
For most integrations, subscribe to `flagUpdated` to receive initial flag values and react to subsequent value changes. `useOnEvent()` attaches the handler and automatically disposes it on unmount.
920
918
921
919
```tsx
922
920
import { useOnEvent } from"@reflag/react-sdk";
@@ -930,7 +928,11 @@ function LoggingWrapper({ children }: { children: ReactNode }) {
930
928
}
931
929
```
932
930
933
-
The event fires once per changed flag with `{ key, flag }`. `flag` contains raw flag data and is undefined when removed. It does not replay existing bootstrapped values; use `useClient().getFlags()` to read current raw flags without fetching or generating checks. Handle identity changes separately if your integration needs to resynchronize traits even when flag values are unchanged.
931
+
`flagUpdated` publishes one initial value per flag during client initialization, including bootstrapped and disabled flags. Bootstrapped values are published after cached overrides are applied, without fetching. Mount the subscription before initialization to receive these events; subscriptions added afterward do not receive a replay. `useClient().getFlags()` also lets you read current raw flags without fetching or generating checks.
932
+
933
+
After initialization, the event fires only when a flag's effective enabled value (including local overrides), config key/payload, or presence changes. Targeting/config versions, evaluation diagnostics, and opt-in metadata alone do not trigger subsequent events. The payload is `{ key, flag }`; `flag` contains raw flag data and is undefined when removed. Handle identity changes separately if your integration needs to resynchronize traits even when flag values are unchanged.
934
+
935
+
Use `flagsUpdated` if you need to observe refreshed raw flag data, even when enabled/config values stay the same. It delivers the full flag map and also fires for metadata-only updates. A refresh returning identical raw flag data does not emit this event. See the [Browser SDK event listeners](../browser-sdk/README.md#event-listeners) for the full event list.
0 commit comments