Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.nexus.westyx.cloud/llms.txt

Use this file to discover all available pages before exploring further.

Installation

.npmrc
@westyx-nexus:registry=https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/npm/
npm install @westyx-nexus/sdk-react
Requires React 18+.

Setup

Wrap your app with NexusProvider:
import { NexusProvider } from '@westyx-nexus/sdk-react';

export default function App() {
  return (
    <NexusProvider
      baseUrl="https://your-service.nexus.westyx.dev"
      apiKey="pk_live_..."
    >
      <MyApp />
    </NexusProvider>
  );
}
The provider suspends rendering until the initial sync completes - components always see a populated cache.

Reading values

import { useNexus, useFlag, useConfig } from '@westyx-nexus/sdk-react';

function CheckoutButton() {
  const newCheckout = useFlag('new-checkout', false);
  const apiBase     = useConfig('API_BASE_URL');

  return newCheckout
    ? <NewCheckoutButton />
    : <LegacyCheckoutButton />;
}

Hooks

HookReturnsDescription
useConfig(key)string | undefinedConfig value; re-renders on change
useFlag(key, default)booleanFlag value; re-renders on change
useNexus()clientFull client access
useEvaluateAB(keys, userId, attrs)Record<string,boolean>A/B evaluation

A/B rollout

import { useEvaluateAB } from '@westyx-nexus/sdk-react';

function FeatureGate({ userId }: { userId: string }) {
  const flags = useEvaluateAB(
    ['checkout-v2', 'new-sidebar'],
    userId,
    { plan: 'pro' },
  );

  return flags['checkout-v2'] ? <CheckoutV2 /> : <CheckoutV1 />;
}

SSE live updates

The SDK opens an SSE stream automatically. Value changes propagate within milliseconds and trigger React re-renders for any component that reads the changed key. The stream uses a 429-aware pre-flight fetch probe with exponential backoff and a 3-strike circuit breaker.

Fallback reasons

ReasonMeaning
'max-errors'3 consecutive transport errors
'rate-limited'Server returned 429
'transport'Generic network failure