Skip to content

Commit 9b05be9

Browse files
authored
fix: in-line docs, un-needed AbortController creation (#1291)
This PR: - clarifies some doc around `useWhenProviderReady` (it really only works with READY) - moves AbortController instantiation so we don't create it every render if we don't need to Signed-off-by: Todd Baert <[email protected]>
1 parent 591f864 commit 9b05be9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

packages/react/src/provider/use-open-feature-client-status.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { ProviderEvents } from '@openfeature/web-sdk';
55

66
/**
77
* Get the {@link ProviderStatus} for the OpenFeatureClient.
8+
* Reacts to changes in provider status.
89
* @returns {ProviderStatus} status of the client for this scope
910
*/
1011
export function useOpenFeatureClientStatus(): ProviderStatus {
1112
const client = useOpenFeatureClient();
1213
const [status, setStatus] = useState<ProviderStatus>(client.providerStatus);
13-
const controller = new AbortController();
1414

1515
useEffect(() => {
16+
const controller = new AbortController();
1617
const updateStatus = () => setStatus(client.providerStatus);
1718
client.addHandler(ProviderEvents.ConfigurationChanged, updateStatus, { signal: controller.signal });
1819
client.addHandler(ProviderEvents.ContextChanged, updateStatus, { signal: controller.signal });

packages/react/src/provider/use-when-provider-ready.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ type Options = Pick<ReactFlagEvaluationOptions, 'suspendUntilReady'>;
1111
* Utility hook that triggers suspense until the provider is {@link ProviderStatus.READY}, without evaluating any flags.
1212
* Especially useful for React v16/17 "Legacy Suspense", in which siblings to suspending components are
1313
* initially mounted and then hidden (see: https://github.com/reactwg/react-18/discussions/7).
14+
*
15+
* NOTE: This hook returns true only when the provider status is {@link ProviderStatus.READY}.
16+
* For other statuses (ERROR, STALE, FATAL, RECONCILING), use {@link useOpenFeatureClientStatus}.
1417
* @param {Options} options options for suspense
1518
* @returns {boolean} boolean indicating if provider is {@link ProviderStatus.READY}, useful if suspense is disabled and you want to handle loaders on your own
1619
*/

0 commit comments

Comments
 (0)