Skip to main content

<NexusProvider>

Creates the client, holds children back until the first sync completes, and closes the client on unmount. See Configuration for config. Without onError, an initialisation failure is re-thrown so a React error boundary can handle it.

Value hooks

Every value hook is built on useSyncExternalStore, so a concurrent render cannot show one flag’s old value beside another’s new one.

useConfig<T>(key): T | undefined

The resolved value of a config key, or undefined when absent. The type parameter is a cast.

useFlag(key, defaultValue = false): boolean

The flag’s is_active state, or defaultValue when the key is absent.

useNexusKind(): string

The service kind the server reported: "backend", "frontend", or "" when the server omitted it.

useNexusSyncedAt(): number

The last successful sync, as epoch milliseconds. A number rather than a Date, because a hook must return a stable value for an unchanged snapshot and a fresh Date is a new reference every read.

useNexusBillingOverdue(): boolean

true while the server answers HTTP 402. Reads keep working from the cache and the refresh loop slows rather than stopping, so this clears on its own once the invoice is settled.

useNexusStreamStatus(): { connected, state }

The live stream’s status. state is one of idle, connecting, connected, reconnecting, polling. Updates on every transition, not only when a sync replaces the cache.

Actions

useNexus(): NexusClient

The client itself. Throws when called outside a <NexusProvider>.

useNexusSync(): () => Promise<void>

Refreshes the cache. Concurrent calls share one request.

useEvaluateAB(): (keys, userId, attributes?: Record<string, string>) => Promise<Record<string, boolean>>

Evaluates flags through the AB Testing endpoint. Always a live call. In-flight requests are aborted when the component unmounts. Rejects with NexusAbAddonNotAvailableError when the add-on is not active.

NexusClient

Usually reached through the hooks. Direct use is for non-React code paths.

Types and constants

NexusConfig, NexusLogger, NexusLogFields, NexusStreamObserver, NexusStreamState, NexusChangeListener, NexusProviderProps, NexusProviderStatus, NexusStreamStatus, PublicApiKey. assertPublicKey(key) narrows a string to PublicApiKey, throwing if it is not a public key - the same check the client applies to apiKey. NOOP_LOGGER, NOOP_STREAM_OBSERVER, FALLBACK_REASON_MAX_ERRORS, FALLBACK_REASON_RATE_LIMITED, FALLBACK_REASON_TRANSPORT.

Errors

See Error handling for the full hierarchy and which errors you will actually encounter.

Removed in v0.16.0

Removed in v0.11.0