diff --git a/packages/react/src/provider/index.ts b/packages/react/src/provider/index.ts index 5d29f9cd3..34a77b53d 100644 --- a/packages/react/src/provider/index.ts +++ b/packages/react/src/provider/index.ts @@ -1,4 +1,5 @@ export * from './provider'; export * from './use-open-feature-client'; export * from './use-when-provider-ready'; +export * from './use-open-feature-client-status'; export * from './test-provider'; diff --git a/packages/react/src/provider/use-open-feature-client-status.ts b/packages/react/src/provider/use-open-feature-client-status.ts index 2539f792f..d8fbba535 100644 --- a/packages/react/src/provider/use-open-feature-client-status.ts +++ b/packages/react/src/provider/use-open-feature-client-status.ts @@ -1,15 +1,19 @@ import { useEffect, useState } from 'react'; import { useOpenFeatureClient } from './use-open-feature-client'; -import type { ProviderStatus } from '@openfeature/web-sdk'; +import { ProviderStatus } from '@openfeature/web-sdk'; import { ProviderEvents } from '@openfeature/web-sdk'; +import { ReactFlagEvaluationOptions } from '../common'; +import { DEFAULT_OPTIONS, useProviderOptions, normalizeOptions, suspendUntilReady } from '../common'; + +type Options = Pick /** * Get the {@link ProviderStatus} for the OpenFeatureClient. * @returns {ProviderStatus} status of the client for this scope */ -export function useOpenFeatureClientStatus(): ProviderStatus { +export function useOpenFeatureClientStatus(options?: Options) { const client = useOpenFeatureClient(); - const [status, setStatus] = useState(client.providerStatus); + const [status, setStatus] = useState(client.providerStatus); useEffect(() => { const updateStatus = () => setStatus(client.providerStatus); @@ -28,6 +32,12 @@ export function useOpenFeatureClientStatus(): ProviderStatus { client.removeHandler(ProviderEvents.Reconciling, updateStatus); }; }, [client]); + // highest priority > evaluation hook options > provider options > default options > lowest priority + const defaultedOptions = { ...DEFAULT_OPTIONS, ...useProviderOptions(), ...normalizeOptions(options) }; + + if (defaultedOptions.suspendUntilReady && status === ProviderStatus.NOT_READY) { + suspendUntilReady(client); + } return status; }